Why does this updateCheckboxGroupInput()
code not work when more than 1 checkboxes are selected. When one checkbox from the above group is selected, the box below should update to show more specific entries. But if more than one checkbox is selected at the top, the code fails. Anyone knows what the issues might be?
Copy from here or bitbucket: https://bitbucket.org/snippets/afolabicrystal/deyay5
ui <- fluidPage(
p("The first checkbox group controls the second"),
checkboxGroupInput("inCheckboxGroup", "Device Class",
c("TV", "Mobile", "Tablet")),
checkboxGroupInput("inCheckboxGroup2", "Device Types",
c("Amazon TV", "Apple TV", "Android Phone", "iPhone", "iPad", "Android Tablet")))
server <- function(input, output, session) {
observe({
x <- input$inCheckboxGroup
# Can also set the label and select items
updateCheckboxGroupInput(session, "inCheckboxGroup2",
label = paste("Device Types", length(x)),
if ('TV' %in% x) {
choices = c("Amazon TV", "Apple TV")
} else if("Mobile" %in% x) {
choices = c("Android Phone", "iPhone")
} else if("Tablet" %in% x) {
choices = c("iPad", "Android Tablet")
} else if (all(c("TV","Mobile") %in% x)) {
choices = c("Amazon TV", "Apple TV", "Android Phone", "iPhone")
} else if (all(c("TV","Tablet") %in% x)) {
choices = c("Amazon TV", "Apple TV", "iPad", "Android Tablet")
} else if (all(c("Mobile","Tablet") %in% x)) {
choices = c("Android Phone", "iPhone", "iPad", "Android Tablet")
} else if (all(c("TV", "Mobile", "Tablet") %in% x)) {
choices = c("Amazon TV", "Apple TV", "Android Phone", "iPhone", "iPad", "Android Tablet")
} else {
choices = character(0)
},
selected = choices
)
})
}
shinyApp(ui, server)