I would like to dynamically update the choices of a checkboxGroupInput
in R Shiny using a vector.
However, a vector used in updateSelectInput
does only create text without boxes whereas directly in checkboxGroupInput
it works.
What is the problem, and how to solve it?
Sadly, I could not find a solution while searching the internet.
MWE:
library(shiny)
ui <- fluidPage(
actionButton("gobutton", "Update Buttons"),
checkboxGroupInput("dynButtons", "Buttons", choices=NULL),
checkboxGroupInput("demo", "Expected result:", choices =c("5-6","5-67","1-1"))
)
server <- function(input, output) {
buttonPressed <- eventReactive(input$gobutton, {
TRUE
})
observeEvent(buttonPressed(), {
updateSelectInput(inputId = "dynButtons", choices = c("5-6","5-67","1-1"))
})
}
shinyApp(ui = ui, server = server)
New contributor
Rol88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.