My question is pretty much the same as this question: Disable an item in selectinput dropdown
I would like to disable items in the selectInput menu, similar to what pickerInput does. However I do not want to use pickerInput, I want to use selectInput/selectizeInput.
One of the responses mentions that you could use HTML to associate a disabled option with the particular value you want to disable. Would anyone be able to provide example code of how to do that in Shiny in the code shell below? Would it be similar to conditional formatting in this thread? R Shiny: Conditional formatting selectInput items
library(shiny)
choices <- c("x", "y", "z")
ui <- fluidPage(
selectizeInput("choices","Choices", choices = choices)
)
server <- function(input, output,session) {}
shinyApp(ui = ui, server = server)
You can do:
library(shiny)
choices <- c("x", "y", "z")
ui <- fluidPage(
selectizeInput(
"choices", "Choices", choices = choices,
options = list(
render = I(
"{
option: function(item, escape) {
if (item.value === 'y') {
return '<div style=\"pointer-events: none; color: #aaa;\">' + escape(item.label) + '</div>';
}
return '<div>' + escape(item.label) + '</div>';
}
}"
)
)
)
)
server <- function(input, output,session) {}
shinyApp(ui = ui, server = server)
But it's much easier with shinyWidgets::pickerInput ;)