Search code examples
javascriptrshinyjquery-selectorsshinyjs

How to use checkbox:nth-child with inline checkboxGroupInput?


In following this question if the checkboxGroupInput has inline=TRUE then disable(selector="#a .checkbox:nth-child(1) label") will no longer disable the option. Is there a tweak to the selector string? I tried changing it to checkbox-inline but that didn't work.


Solution

  • With the inline=TRUE parameter, the label elements are not under a div, therefore you can make the reference directly to the labels.

    library(shiny)
    
    ui <- shinyUI(fluidPage(
      shinyjs::useShinyjs(),
      checkboxGroupInput("a", "A", choices = 1:7, inline = TRUE)
    ))
    
    server <- shinyServer(function(input, output, session) {
      observeEvent(input$a, shinyjs::disable(selector="#a label:nth-child(1)"))
    })
    
    shinyApp(ui, server)