Reputation: 6931
I have two checkboxGroupInputs
and two buttons.
The button "All" selects everything in both checkboxGroupsInputs
, and works correctly.
The button "None" is supposed to clears everything in both checkboxGroupInputs
, but only ever clears the first checkbox.
If I swap the order of the updateCheckboxGroupInputs
in the listener for the "None" button then the other checkbox-group does not clear.
What I would like is a single button/listener to clear both groups of checkboxes.
library(shiny)
# Define UI
ui <- fluidPage(
actionButton("all_button", "All"),
actionButton("none_button", "None"),
checkboxGroupInput("A_checkbox", label = "A", choices = c('a','b','c')),
checkboxGroupInput("Z_checkbox", label = "Z", choices = c('x','y','z'))
)
# Define server logic
server <- function(input, output, server, session) {
observeEvent(input$all_button,{
# both update
updateCheckboxGroupInput(session, "A_checkbox", selected = c('a','b','c'))
updateCheckboxGroupInput(session, "Z_checkbox", selected = c('x','y','z'))
})
observeEvent(input$none_button,{
# the second one does not update
updateCheckboxGroupInput(session, "A_checkbox", selected = NA)
updateCheckboxGroupInput(session, "Z_checkbox", selected = NA)
})
}
# Run the app
shinyApp(ui = ui, server = server)
Upvotes: 1
Views: 153
Reputation: 694
You can not use NA but character(0) to deselect checkbox group input.
observeEvent(input$none_button,{
updateCheckboxGroupInput(session, "A_checkbox", selected = character(0))
updateCheckboxGroupInput(session, "Z_checkbox", selected = character(0))
})
Please type ?updateCheckboxGroupInput in your console and see the help.
Upvotes: 2