3

I have a below shiny code, I am trying to disable single radio button choice from grouped radio buttons. I can disable complete radio button using shinyjs::disable() function. But, having trouble disabling single choice.

library(shiny)
library(shinyjs)
library(shinyWidgets)
if (interactive()) {

  ui <- fluidPage(
    useShinyjs(),
    radioGroupButtons(inputId = "somevalue", choices = c("A", "B", "C")),
    verbatimTextOutput("value")
  )
  server <- function(input, output) {
    output$value <- renderText({ input$somevalue })

    shinyjs::disable(id="somevalue")

  }
  shinyApp(ui, server)
}
Rushabh Patel
  • 2,672
  • 13
  • 34

1 Answers1

4

You can do

runjs("$('input[value=B]').parent().attr('disabled', true);")

or

runjs('$("#somevalue button:eq(1)").attr("disabled", true);')

or

disable(selector = "#somevalue button:eq(1)")
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • is it possible for us to achieve this using `shinyjs::disable` function? Because, I want to enable and disable based on selectors. – Rushabh Patel Oct 09 '19 at 19:18
  • @RushabhPatel This is my third solution. No need to write `shinjs::` when `shinyjs` is loaded. – Stéphane Laurent Oct 09 '19 at 19:21
  • For the first of these answers, how does it identify for which input it should disable? If there were two radiogroupbuttons with the value B as a response, would it just disable them both? – Jamie Aug 31 '21 at 22:12