2017-01-25 29 views
0

我是新來發現閃閃發光的反應性。我想使用selectInput來選擇一個行的名稱,並讓該表顯示該行然後是幾列。例如,如果我的行是人(「Anna」,「Tim」,「Larry」),我的列是變量(「A」,「B」,「C」),我希望selectInput顯示「安娜「和數據表來顯示只有安娜的變量A,B和C.選擇要在閃亮的數據表中顯示的行selectInput

我被困在如何做到這一點。

ui <- shinyUI(
fluidPage(
fluidRow(
column(2, selectInput("name", "Select a Name:", 
         c("Anna"= "smith.anna", 
         "Tim" = "miller.tim"))), 
column(6, "People Table", tableOutput("mytable") 
)))) 

server <- function(input, output) { 
output$mytable <- renderTable({ 
mydataset[mydataset, input$name]}) 
} 

我很確定這是我的服務器功能,搞砸了,但所有的提示都很有幫助!謝謝!

+0

mydataset [mydataset,輸入$名稱]似乎是問題。你可能是指mydataset [輸入$ name,]?無論如何,一個可重複的例子總是有幫助的,如果你正在尋求幫助。 – BigDataScientist

回答

0

見我的評論:

mydataset <- data.frame(A = 1:3, B = 4:6, C = 7:9) 
row.names(mydataset) <- c("smith.anna", "miller.tim", "page.larry") 


ui <- shinyUI(
    fluidPage(
    fluidRow(
     column(2, selectInput("name", "Select a Name:", 
          c("Anna"= "smith.anna", 
           "Tim" = "miller.tim"))), 
     column(6, "People Table", tableOutput("mytable") 
    )))) 

server <- function(input, output) { 
    output$mytable <- renderTable({ 
    mydataset[input$name, ] 
    }) 
} 

shinyApp(ui, server) 
+1

真的很有幫助!謝謝! – tika