Select ALL option when using selectInput in shiny

9,484 views
Skip to first unread message

Rajarshi Bhadra

unread,
Jun 29, 2015, 12:22:01 PM6/29/15
to shiny-...@googlegroups.com
Is there any way I can introduce the select all option in the list of options available while using selectInput in Shiny?

Winston Chang

unread,
Jul 1, 2015, 5:06:44 PM7/1/15
to Rajarshi Bhadra, shiny-discuss
There doesn't appear to be a built-in way to do that with the selectize.js library (which selectInput uses by default).

But you could add an option called "Select All", and then, on the server side, use observe() combined with updateSelectInput, to select all the items.  For example:

choices <- c("Select All", "choice 1", "choice 2", "choice 3")

shinyApp(
  ui = fluidPage(
    selectInput("myselect", "Select box", choices, multiple = TRUE),
    verbatimTextOutput("selected")
  ),
  server = function (input, output, session) {
    observe({
      if ("Select All" %in% input$myselect) {
        # choose all the choices _except_ "Select All"
        selected_choices <- setdiff(choices, "Select All")
        updateSelectInput(session, "myselect", selected = selected_choices)
      }
    })
        
    output$selected <- renderText({
      paste(input$myselect, collapse = ", ")
    })
  }
)



-Winston

On Mon, Jun 29, 2015 at 11:22 AM, Rajarshi Bhadra <bhadrar...@gmail.com> wrote:
Is there any way I can introduce the select all option in the list of options available while using selectInput in Shiny?

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/0ce72cad-4799-4d7c-9d96-2d75906092dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages