I am trying to grey out a selectInput choice from the dropdown after selecting it from the dropdown and clicking a checkboxInput. Below is some example code where I use shinyjs::disable. However, the disable function disables the whole selectInput before I have even selected the checkbox. I would like the selectInput current choice to be disabled after the checkbox is selected:
library(shiny)
ui <- fluidPage(
shinyjs::useShinyjs(),
sidebarLayout(
sidebarPanel(
selectInput("name","Pick Name:",c("Alice","Austin"),selected = "Alice"),
br()
,width = 3),
mainPanel(
tabsetPanel(
tabPanel(
"Tab",
br(),
checkboxInput("complete","Complete?"),
br()
)
)
)
)
)
server <- function(input, output) {
observeEvent(input$complete, shinyjs::disable("name"))
}
# Run the application
shinyApp(ui = ui, server = server)
Also, does anyone know how this functionality can be applied across multiple sessions?
To disable the select options we can using shinyWidgets
package and its pickerinput
, such as:
library(shiny)
library(shinyWidgets)
names <- c("Alice","Austin","Alex")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
pickerInput("myname","Pick Name:",choices = names),
br(),width = 3),
mainPanel(
tabsetPanel(
tabPanel(
"Tab",
br(),
checkboxInput("complete","Complete?",FALSE),
br()
)
)
)
)
)
server <- function(input, output,session) {
observeEvent(input$complete, {
print(input$complete)
disabled_choices <- names==c("Alex")
updatePickerInput(
session = session, inputId = "myname",
choices = names,
choicesOpt = list(
disabled = disabled_choices,
style = ifelse(disabled_choices,
yes = "color: rgba(119, 119, 119, 0.5);",
no = "")
)
)
}, ignoreInit = TRUE)
}
# Run the application
shinyApp(ui = ui, server = server)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.