【问题标题】:R Shiny filter on data frame数据帧上的R闪亮过滤器
【发布时间】:2015-05-19 15:38:59
【问题描述】:

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

举个例子(来自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 的一些想法:使用点击actionButton 时出现的checkboxGroupInput

欢迎各种建议。谢谢

【问题讨论】:

  • 我很清楚,您是否正在寻找一种仅在单击按钮时才显示复选框的方法?
  • 没错!并在应用过滤器后隐藏

标签: r shiny


【解决方案1】:

这可以帮助您完成大部分工作,但是一旦您选择了一个选项,它就无法隐藏复选框:

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

【讨论】:

  • 感谢您的快速答复。我们可以用类似toggleButton的东西代替actionButton吗?
  • 我在“shinyBS”中找到了它:bsButton(..., type = "toggle")
  • 要通过第二次点击收回列表,请将output$checkbox 中的第二个条件更改为input$show_checkbox %% 2 == 0。但是,重新打开它会重新初始化过滤。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-09
相关资源
最近更新 更多