2014-10-01 77 views
4

我的闪亮应用程序有另一个问题。目标是当用户按下一个actionButton时禁用我的应用中的一些输入。我发现this解决方案,它适用于textinputs和数字输入,但奇怪的不是selectinput或selectizeinput。我知道解决方案包含JavaScript,但我不知道如何。禁用选择输入闪亮

在此先感谢您的帮助!

编辑:

也许我没有说清楚。对不起大家!我将添加必要的代码块。

这是链接的禁用功能。它适用于actionButtons和数字输入,但不适用于选择或选择输入。

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,但我甚至不知道基本原理是诚实的。我已经尝试了不同的probs,如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")) 

那么,有没有其他方法来禁用选择/选择输入?

再次感谢:)

+0

我不知道为什么这个问题是downvoted,但也许你可以通过附加的几张截图使其更清晰 – Alex 2014-10-02 01:39:00

+0

嘿, 没有人可以帮忙吗? 谢谢:) – Richard 2014-10-07 14:09:50

回答

4

解决方法:你可以使用我的包shinyjs为 - 你只需要调用shinyjs::disable(id),它会工作。


解释为什么它不是超级简单:问题是,当你使用selectize,它创建了另一个选择框,这只是漂亮的HTML,但它不是一个真正的HTML输入元素,因此它不给回应disabled属性像真正的HTML标签一样。如果您查看selectize.js文档,禁用selectize可以使用JS完成,但闪亮并不方便。 :(

如果你不使用selectize(selectInput(selectize = FALSE)),禁止将工作得很好。