2
votes

I need to apply a filter on data frame in my 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 pivot table filter

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

All kind of suggestions are welcome. Thank's

1
Just so I'm clear, are you looking for a way to have the checkbox only show up when the button is clicked?Quinn Weber
Exactly! And hidden after apply a filterAndriy T.

1 Answers

3
votes

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