r - 禁用 selectInput/selectizeInput 中的项目
问题描述
我的问题和这个问题差不多:Disable an item in selectinput dropdown
我想禁用 selectInput 菜单中的项目,类似于 pickerInput 所做的。但是我不想使用pickerInput,我想使用selectInput/selectizeInput。
其中一个回复提到您可以使用 HTML 将禁用的选项与您要禁用的特定值相关联。任何人都可以在下面的代码外壳中提供如何在 Shiny 中执行此操作的示例代码吗?它会类似于这个线程中的条件格式吗?R Shiny:条件格式选择输入项
library(shiny)
choices <- c("x", "y", "z")
ui <- fluidPage(
selectizeInput("choices","Choices", choices = choices)
)
server <- function(input, output,session) {}
shinyApp(ui = ui, server = server)
解决方案
你可以做:
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)
推荐阅读
- javascript - 在javascript中计数和重置
- javascript - 使用纯javascript将鼠标悬停在视频上时如何播放视频
- ruby - 向 Middleman 添加自定义 Markdown
- c# - 用一个词多次拆分字符串?
- html - 在换行符中处理边距时,是否有更简单的“calc”替代方法?
- video-streaming - HLS 视频流和聊天消息同步
- ios - 将 AKAudioFile 拆分为由静音分隔的块
- vb.net - VB.NET 不能将 EOF 和 BOF 与 ADODB 记录集一起使用
- typescript - TypeScript:条件类型并使用布尔参数来控制返回类型
- sql-server - 字符串或二进制数据将从 SQL Server 截断到 PostgreSQL 链接服务器