How do I disable an item in a selectInput() dropdown menu?
For example;
library(shiny)
ui <- fluidPage(selectInput("id1","Select",choices=c("A","B","C")))
server <- function(input, output) {}
shinyApp(ui, server)

Say, for whatever reason, option C cannot be selected due to some logic. I would like the user to be able to see all the options, but have option C disabled/unselectable.
You can do this using pickerInput from package shinyWidgets :
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
pickerInput(
inputId = "id1",
label = "Select :",
choices = c("A", "B", "C"),
multiple = FALSE,
choicesOpt = list(
disabled = c("A", "B", "C") %in% c("C")
)
),
verbatimTextOutput(outputId = "result")
)
server <- function(input, output) {
output$result <- renderPrint(input$id1)
}
shinyApp(ui, server)
That's also possible to do that from the server, see example in ?updatePickerInput
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With