Shiny: all-or-nothing selector for checkbox groups

Created on 16 Nov 2012  ·  3Comments  ·  Source: rstudio/shiny

Would love the checkboxGroupInput to (optionally) have a select all/select none box associated with the group.

Most helpful comment

I think you can achieve this by updateCheckboxGroupInput(). An example:

myChoices <- letters[1:5]
runApp(list(
  ui = basicPage(
    checkboxGroupInput('foo', 'FOO', myChoices),
    checkboxInput('bar', 'All/None')
  ),
  server = function(input, output, session) {
    observe({
      updateCheckboxGroupInput(
        session, 'foo', choices = myChoices,
        selected = if (input$bar) myChoices
      )
    })
  }
))

All 3 comments

I think you can achieve this by updateCheckboxGroupInput(). An example:

myChoices <- letters[1:5]
runApp(list(
  ui = basicPage(
    checkboxGroupInput('foo', 'FOO', myChoices),
    checkboxInput('bar', 'All/None')
  ),
  server = function(input, output, session) {
    observe({
      updateCheckboxGroupInput(
        session, 'foo', choices = myChoices,
        selected = if (input$bar) myChoices
      )
    })
  }
))

I love this! An elegant solution!

Could it be relevant to reopen that suggestion?

When using shiny with flexdashboard, it would be easier for basic users to have a simple option directly within checkboxGroupInput ().

Best regards

Was this page helpful?
0 / 5 - 0 ratings