Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditionalPanel javascript conditions in shiny: is there R %in% operator in javascript?

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")
                                                        )
like image 330
Marcin Kosiński Avatar asked Apr 14 '15 20:04

Marcin Kosiński


1 Answers

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

like image 183
BartekCh Avatar answered Nov 10 '22 05:11

BartekCh