2014-10-01 98 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)),禁止將工作得很好。