我的 Shiny 应用程序还有另一个问题。目标是在用户按下 actionButton 时禁用我的应用程序中的某些输入。我找到了 this解决方案,它适用于文本输入和数字输入,但奇怪的是不适用于 selectinput 或 selectizeinput。我知道解决方案包含以某种方式使用 javascript,但我不知道如何使用。
在此先感谢您的帮助!
编辑:
可能我说的不够清楚。对不起大家!我将添加必要的代码块。
这是链接中的禁用功能。它适用于 actionButtons 和数字输入,但不适用于 select 或 selectize 输入。
disableActionButton <- function(id,session) {
session$sendCustomMessage(type="jsCode",
list(code= paste("$('#",id,"').prop('disabled',true)"
,sep="")))
disableselectButton <- function(id,session) {
session$sendCustomMessage(type="jsCode",
list(code= paste("$('#",id,"').prop('select',false)"
,sep="")))
disableselectButton <- function(id,session) {
session$sendCustomMessage(type="jsCode",
list(code= paste("$('#",id,"').prop('hide',false)"
,sep="")))
这是未被禁用的输入示例。正如我所说,解决方案可能存在于 javascript 中,但老实说,我什至不知道基础知识。我已经尝试了不同的概率,例如 hide=true 或 select=false,但都不起作用(您也可以在上面看到不起作用的函数)。
selectInput("algorithmicMethod1",
label=h5("Berechnungsalgorithmus erster Wahl"),
c("RoT","Pickands"),
selected="RoT"),
conditionalPanel(condition="input.algorithmicMethod1 =='RoT'",
selectInput("algorithmicMethod2",
label=h5("Berechnungsalgorithmus zweiter Wahl"),
"Pickands",
selected="Pickands")),
conditionalPanel(condition="input.algorithmicMethod1 =='Pickands'",
selectInput("algorithmicMethod2",
label=h5("Berechnungsalgorithmus zweiter Wahl"),
"RoT",
selected="RoT"))
那么,还有其他方法可以禁用 select/selectize-Inputs 吗?
再次感谢。:)
最佳答案
解决办法:可以用我的包shinyjs为此 - 您只需调用 shinyjs::disable(id)
即可。
解释为什么它不是 super 简单:问题是当您使用 selectize 时,它会创建另一个选择框,它只是漂亮的 HTML 但它不是真正的 HTML 输入元素,因此它不会响应 disabled
属性就像真正的 HTML 标签一样。如果您查看 selectize.js 文档,可以使用 JS 禁用 selectize,但是使用 shiny 不是很方便。 :(
如果您不使用 selectize (selectInput(selectize = FALSE)
),禁用将正常工作。
关于javascript - 禁用选择输入 Shiny ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26142525/