禁用Shiny中的Selectize输入

5
我有一个关于我的Shiny应用程序的问题。目标是在用户按下actionButton时禁用应用程序中的某些输入。我找到了this解决方案,对于文本输入和数字输入有效,但对于selectinput或selectizeinput却奇怪地无效。我知道该解决方案包含一些使用JavaScript的内容,但我不知道如何操作。
感谢您的帮助!
编辑:
也许我没有表述清楚。抱歉!我将添加必要的代码块。
这是来自链接的disablefunction。它可以很好地与actionButtons和numeric Inputs配合使用,但不能与select或selectize Input配合使用。
 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?

再次感谢。:)


我不知道为什么这个问题被点踩,但也许你可以通过附上一些你的闪亮应用程序工作流程的截图来让它更清晰。 - Alex
嘿,没有人能帮忙吗?谢谢 :) - Richard
1个回答

6
解决方案:你可以使用我的包shinyjs - 只需调用shinyjs::disable(id)即可。
为什么这不是非常简单的问题:问题在于当您使用selectize时,它会创建另一个选择框,它只是漂亮的HTML,但不是真正的HTML输入元素,因此它不像真正的HTML标签那样响应disabled属性。如果查看selectize.js文档,可以使用JS禁用selectize,但与shiny一起使用不太方便。 :(
如果你没有使用selectize(selectInput(selectize = FALSE)),禁用功能就能正常工作。

我已经尝试了使用shinyWidgets中的pickerInput,但没有成功。你知道原因吗? - David Díaz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接