Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Selectize Input Shiny

I have another problem with my shiny app. The goal is to disable some inputs in my app when the user presses an actionButton. I found this solution, which works fine for the textinputs and the numeric inputs, but oddly not for selectinput or selectizeinput. I know the solution contains somehow using javascript, but I don't know how.

Thanks in advance for the help!

Edit:

Perhaps I haven't made it clear enough. Sorry guys! I'll add the necessary code chunks.

This is the disablefunction from the link. It works fine with actionButtons and numeric Inputs, but not with select or 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="")))

This is an example of the Inputs which don't get disabled. As I said the solution lies, probably, in javascript, but I don't even know the fundamentals to be honest. I've tried different probs like hide=true oder select=false, which didn't work (you can see the functions that did not work above as well).

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"))

So, is there any other way to disable the select/selectize-Inputs?

Thanks again.:)

like image 400
Richard Avatar asked Oct 01 '14 13:10

Richard


1 Answers

Solution: you can use my package shinyjs for that - you just call shinyjs::disable(id) and it will work.


Explanation why it's not super simple: the problem is that when you use selectize, it creates another select box that is just pretty HTML but it's not a real HTML input element, so it doesn't respond to the disabled property like real HTML tags do. Disabling a selectize can be done using JS if you look at the selectize.js documentation, but it's not very convenient with shiny. :(

If you don't use selectize (selectInput(selectize = FALSE)), disabling will work just fine.

like image 166
DeanAttali Avatar answered Oct 14 '22 02:10

DeanAttali