9

I am trying to build a shiny application using the conditionalPanel function from shiny package. The condition should be written in JavaScript but I would like to be able to use a condition as follows (written in R)

"TP53" %in% unlist(input$ModelVariables)

the documenatation states:

condition - A JavaScript expression that will be evaluated repeatedly to determine whether the panel should be displayed.

I'm not familiar with JavaScript at all. I've tried input.ModelVariables == 'TP53' but this doesn't work when input.ModelVariables has length bigger than 1.

My sidebarPanel fragment with conditionalPanel is below

                    checkboxGroupInput("ModelVariables", 
                                       label = h3("Which variables to view?"),
                                       choices = list( "cohort",
                                                       "stage",        
                                                       "therapy",             
                                                       "TP53",
                                                       "MDM2" ),
                                       selected = list("TP53")
                                  ),
                    conditionalPanel(condition = "'TP53' in unlist(input.ModelVariables)",
                                     checkboxGroupInput("ModelVariablesTP53", 
                                                        label = h3("Which mutations to view?"),
                                                        choices = list( "Missense",
                                                                        "Other",        
                                                                        "WILD"),
                                                        selected = list("Missense",
                                                                        "Other",        
                                                                        "WILD")
                                                        )
3
  • Have you tried 'TP53' in input.ModelVariables in JavaScript?
    – Alex A.
    Apr 14, 2015 at 21:02
  • This 'TP53' in input.ModelVariables doesn't work since input.ModelVariables is a list. And condition="'TP53' in unlist(input.ModelVariables)" makes condtitionalPanel permanent.
    – Marcin
    Apr 14, 2015 at 21:37
  • I've updated my question with more code.
    – Marcin
    Apr 14, 2015 at 22:07

1 Answer 1

15

According to this answer this condition should work (and it works for me) condition = "input.ModelVariables.indexOf('TP53') > -1"

1
  • This is awesome, was looking for this exact answer for a while. Dec 17, 2020 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.