在 Shiny 中禁用 pickerInput

Disable pickerInput in Shiny

我使用 shinyWidgets 中的 pickerInput,我想禁用它。为此,我使用了函数 disable 形式的 shinyjs 包,但它不起作用。但是当我使用 selectInput 时,它就起作用了。这是我的代码:

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)

我们该如何解决?

一些帮助将不胜感激

您可以将其包装在 div 中并将其禁用。请注意,这有点装饰性,使用 shinyjs::disable("somevalue") 将禁用它,因为不会将任何操作推送到 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)