使用selectInput选择要在Shiny数据表中显示的行

时间:2017-01-25 13:48:36

标签: shiny reactive

我很想知道闪亮的反应性。我想使用selectInput来选择行的名称,并让表只显示该行,然后显示几列。

例如,如果我的行是人(" Anna"," Tim"," Larry"),我的列是变量(" A& #34;," B"," C")我希望selectInput显示" Anna"和数据表只显示Anna的变量A,B和C.

我坚持如何做到这一点。

 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]})
 }

我很确定我的服务器功能搞砸了,但所有提示都很有帮助!谢谢!

1 个答案:

答案 0 :(得分:1)

查看我的评论:

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)