Skip to content

Disable radioGroupButtons with checkIcon #311

@benmarchi

Description

@benmarchi

This issue is related to #281.

When checkIcon is specified for a radioGroupButtons disabling the input does not function as expected. Specifically, when the input is disable, it is still possible to change the selection by clicking on the square check box next to the option name. Clicking elsewhere on a button is disabled.

Example app

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
    
    checkboxGroupButtons(
        inputId = "check",
        choices = head(month.name),
        label = "Check buttons"
    ),
    radioGroupButtons(
        inputId = "radio",
        choices = head(month.name),
        label = "Radio buttons",
        checkIcon = list(
            yes = icon("check-square"),
            no = icon("square-o")
        )
    ),
    
    tags$b("Check"),
    verbatimTextOutput(outputId = "valCheck"),
    tags$b("Radio"),
    verbatimTextOutput(outputId = "valRadio"),
    
    checkboxInput(inputId = "disable", label = "Disable?", value = FALSE),
    checkboxInput(inputId = "disable1", label = "Disable march?", value = FALSE),
    checkboxInput(inputId = "disable2", label = "Disable february & april?", value = FALSE)
)

server <- function(input, output, session) {
    
    output$valCheck <- renderPrint({
        input$check
    })
    output$valRadio <- renderPrint({
        input$radio
    })
    
    observeEvent(input$disable, {
        updateCheckboxGroupButtons(
            session = session, 
            inputId = "check",
            disabled = input$disable
        )
        updateRadioGroupButtons(
            session = session, 
            inputId = "radio",
            disabled = input$disable
        )
    }, ignoreInit = TRUE)
    
    observeEvent(input$disable1, {
        updateCheckboxGroupButtons(
            session = session, 
            inputId = "check",
            disabledChoices = if (input$disable1) "March" else NULL
        )
        updateRadioGroupButtons(
            session = session, 
            inputId = "radio",
            disabledChoices = if (input$disable1) "March" else NULL
        )
    }, ignoreInit = TRUE)
    
    observeEvent(input$disable2, {
        updateCheckboxGroupButtons(
            session = session, 
            inputId = "check",
            disabledChoices = if (input$disable2) c("February", "April") else NULL
        )
        updateRadioGroupButtons(
            session = session, 
            inputId = "radio",
            disabledChoices = if (input$disable2) c("February", "April") else NULL
        )
    }, ignoreInit = TRUE)
    
}

shinyApp(ui = ui, server = server, options = list(launch.browser = TRUE))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions