[英]R Shiny filter on data frame
I need to apply a filter on data frame in my Shiny App. 我需要在Shiny App中对数据框应用过滤器。 I am looking for some button (small one) that opens a multiselect list of values of a specific column.
我正在寻找一些按钮(小按钮),用于打开特定列的值的多选列表。 Something like Excel's table filter
类似于Excel的表格过滤器
As an example (from 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, ]
})
}
))
Some idea from the widget fallery : use checkboxGroupInput
that appears clicking on actionButton
从一些想法的小部件fallery :使用
checkboxGroupInput
是出现在点击actionButton
All kind of suggestions are welcome. 欢迎各种建议。 Thank's
谢谢
This gets you most of the way, but it doesn't have a way to hide the checkbox once you have selected an option: 这可以为您提供大部分帮助,但是一旦选择了一个选项,便无法隐藏该复选框:
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, ]
})
}
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.