I need to restrict the user's ability to select radio buttons, yet show them at all times. I use shinyjs::disable
to disable the button and updateRadioButtons
to update the selection , but it doesn't seem to work correctly. Only the update seems to work, not the disabling My code:
library(shiny)
library(shinyjs)
server = shinyServer(function(input, output, session) {
observeEvent(input$toggle, {
if (input$toggle == "enable") {
updateRadioButtons(session, "button1", "",
c("one" = "one", "two" = "two"),
inline = T, selected = "one")
shinyjs::enable("button1")
}
if (input$toggle == "disable") {
updateRadioButtons(session, "button1", "",
c("one" = "one", "two" = "two"),
inline = T, selected = "two")
shinyjs::disable("button1")
}
})
})
ui = shinyUI(
fluidPage(
shinyjs::useShinyjs(),
radioButtons("toggle", "",
c("enable" = "enable", "disable" = "disable"), inline = T),
radioButtons("button1", "",
c("one" = "one", "two" = "two"), inline = T)
))
shinyApp(ui=ui,server=server)