Reputation: 5677
I don't know if this is a bug of just a feature, but the updateCheckboxGroupInput
function in Shiny is not working consistently. When I update the group with selected=FALSE
to deselect all the choices, the related reactive components (observer, UI elements) doesn't change anything. I know that there are many ways to do this task, my point here is to show the lack of consistency of the updateCheckboxGroupInput
with the selected
parameter.
Here is simplified example that represents the problem using a couple of action buttons to select/deselect all the choices on the group. After updating with selected=FALSE
, all the choices are deselected but the change does not affect the reactive components associated (in this case verbatimTextOutput) as is the case of selecting all.
Can someone explain me why the updateCheckboxGroupInput
is not working as expected?
choices <- letters[1:5]
runApp(list(
ui = basicPage(
checkboxGroupInput('chkGrp', 'Options', choices),
actionButton("all","All"),
actionButton("none","None"),
verbatimTextOutput("value")
),
server = function(input, output, session) {
output$value <- renderPrint({ input$chkGrp })
observe({
if ( is.null(input$all) || input$all == 0)
return()
updateCheckboxGroupInput(session,"chkGrp",selected=choices )
})
observe({
if ( is.null(input$none) || input$none == 0)
return()
updateCheckboxGroupInput(session,"chkGrp",selected=FALSE)
})
}
))
Upvotes: 2
Views: 1594
Reputation: 29387
When you use the updateCheckboxGroupInput
you still have to provide what goes in there.
#rm(list = ls())
library(shiny)
choices <- letters[1:5]
runApp(list(
ui = basicPage(
checkboxGroupInput('chkGrp', 'Options', choices),
actionButton("all","All"),
actionButton("none","None"),
verbatimTextOutput("value")
),
server = function(input, output, session) {
output$value <- renderPrint({ input$chkGrp })
observe({
if ( is.null(input$all) || input$all == 0)
return()
updateCheckboxGroupInput(session,"chkGrp",selected=choices )
})
observe({
if ( is.null(input$none) || input$none == 0)
return()
updateCheckboxGroupInput(session,"chkGrp",choices = choices,selected=NULL)
})
}
))
Upvotes: 2