R Shiny过滤数据框

时间:2015-05-19 15:39:00

标签: r shiny

我需要在我的Shiny App中对数据框应用过滤器。 我正在寻找一个按钮(小一个)打开一个特定列的值的多选列表。类似于Excel的表格过滤器

Excel pivot table filter

作为一个例子(来自another topic):

library(shiny)
shiny::runApp(list(
  ui = fluidPage(
    checkboxGroupInput("specy", "Specy", choices = levels(iris$Species)),
    tableOutput("content")
  ),
  server = function(input, output, session) {
    output$content <- renderTable({
      iris[iris$Species == input$specy, ]
    })
  }
))

来自the widget fallery的一些想法:使用checkboxGroupInput点击actionButton

欢迎各种建议。感谢的

1 个答案:

答案 0 :(得分:3)

这可以帮到你,但是一旦你选择了一个选项,它就无法隐藏复选框:

library(shiny)
shiny::runApp(list(
  ui = fluidPage(
    actionButton("show_checkbox", "Show Choices"),
    uiOutput("checkbox"),
    tableOutput("content")
  ),
  server = function(input, output, session) {
    output$checkbox <- renderUI({
        if ( is.null(input$show_checkbox) ) { return(NULL) }
        if ( input$show_checkbox == 0 ) { return(NULL) }
        return(checkboxGroupInput("specy", "Specy", choices = levels(iris$Species)))
    })
    output$content <- renderTable({
        if ( is.null(input$specy) ) { return(iris) }
        if ( length(input$specy) == 0 ) { return(iris) }
      iris[iris$Species == input$specy, ]
    })
  }
))