disabling single choice of a checkboxGroupInput

1,178 views
Skip to first unread message

Manali Kruthiventi

unread,
Feb 14, 2017, 9:33:33 AM2/14/17
to Shiny - Web Framework for R
Hi,

I want to disable few choices of a checkboxGroupInput.

I am trying to use an id of the choices to disable it, but it's not working. Below is the cove I am trying:

ui.R
checkboxGroupInput("chkilcounty", label = h5("County", style="font-size: 15.0px;"),
                                                 choices = list(" " = "Summary", " " = "ELT", " " = "AEP", " " = "OEP",, " " = "AAL", " " = "PLT"),
                                                 selected = NULL),

server.R
shinyjs::disable("Summary")

Note: choices labels are kept blank intentionally, as we do not want to display anything on the screen.
Any help or pointers would be really appreciated.

Thank you,
Manali

Bárbara Borges

unread,
Feb 15, 2017, 2:09:07 PM2/15/17
to Shiny - Web Framework for R
You need to use a more complex css selector (not just an id). You have to inspect the html to understand it. Here's a minimal example:

ui <- fluidPage(
    useShinyjs(),
    checkboxGroupInput("variable", "Variables to show:",
        c("Cylinders" = "cyl",
            "Transmission" = "am",
            "Gears" = "gear")),
    actionButton("btn", "Disable 'Cylinder' variable"),
    tableOutput("data")
)

server <- function(input, output) {
    output$data <- renderTable({
        head(mtcars[, c("mpg", input$variable), drop = FALSE])
    }, rownames = TRUE)
    
    observeEvent(input$btn, {
        shinyjs::disable(selector = "#variable input[value='cyl']")
    })
}

shinyApp(ui, server)

Manali Kruthiventi

unread,
Feb 21, 2017, 8:25:01 AM2/21/17
to Shiny - Web Framework for R
Hi Barbara,

It worked for me. Thanks for your inputs.

Regards,
Manali
Reply all
Reply to author
Forward
0 new messages