Search code examples
rshinyshinydashboardshinyjsshinywidgets

Disable pickerInput in Shiny


I use pickerInput from shinyWidgets and I would like to disable it. For this purpose, I used the function disable form shinyjs package but it's doesn't work. But when I use selectInput it's work. This is my code :

library(shiny)
library(shinyjs)
library(shinyWidgets)

##### UI ####

header <- dashboardHeader()
sidebar <- dashboardSidebar()
body <- dashboardBody(
  useShinyjs(),
  
  
  pickerInput(
    inputId = "somevalue",
    label = "pickerInput",
    choices = c("one", "two")
  ),
  
  br(),
  selectInput(inputId = "test", label = "selectInput",
              choices = c("B", "C")
  )
)

ui <- dashboardPage(header, sidebar, body)

##### SERVER ####
server <- function(session, input, output) { 
  
  shinyjs::disable("somevalue") # doesnt work
  shinyjs::disable("test") # ok it's fine
  
}

shinyApp(ui, server)

How can we fix it ?

Some help would be appreciated


Solution

  • You can wrap it in a div and disable that. Note that this is somewhat cosmetic, using the shinyjs::disable("somevalue") will disable it, as no action will be pushed to server.R

    library(shiny)
    library(shinyjs)
    library(shinyWidgets)
    library(shinydashboard)
    
    ##### UI ####
    
    header <- dashboardHeader()
    sidebar <- dashboardSidebar()
    body <- dashboardBody(
      useShinyjs(),
      div(id="somediv",
          pickerInput(
            inputId = "somevalue",
            label = "pickerInput",
            choices = c("one", "two")
          )
      ),
      
      br(),
      selectInput(inputId = "test", label = "selectInput",
                  choices = c("B", "C")
      )
    )
    
    ui <- dashboardPage(header, sidebar, body)
    
    ##### SERVER ####
    server <- function(session, input, output) { 
      
      shinyjs::disable("somediv") # ok it's fine
      shinyjs::disable("test") # ok it's fine
      
    }
    
    shinyApp(ui, server)