I am trying to create two checkboxInputs in an R Shiny app which behave in a way that only one can be enabled at a time but having neither enabled should also be an option (essentially they both can't be true at the same time).
ui <- fluidPage(
checkboxInput("box1", "Test1", value = F),
checkboxInput("box2", "Test2", value = F)
)
server <- function(input, output, session) {
observeEvent(input$box1, {
if (input$box2){
updateCheckboxInput(session,
"box2",
value = F)
}
})
observeEvent(input$box2, {
if (input$box1){
updateCheckboxInput(session,
"box1",
value = F)
}
})
}
shinyApp(ui = ui, server = server)
The above app almost does what I want but selecting box2 when box1 is selected just disables both of them instead of selecting box2 and unselecting box1. Ideally, when one of the boxes are selected, selecting the other one should disable the former and enable the latter. Is this possible without using radioButtons?