Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using conditionalPanel with values from checkboxGroupInput

Tags:

r

shiny

I want to use checkboxGroupInput and then, if a certain box is checked, i want a conditionalPanel. A toy example is here:

shinyUI(fluidPage( 

 sidebarLayout(
  sidebarPanel(
      checkboxGroupInput("items","Which Item?",
          choices=c("A","B","C","D")),
        conditionalPanel( condition = "input.items == 'D'",       
          numericInput("n","n",value=50,min=0,max=100,step=1)
        )
      ),       
      mainPanel(
      uiOutput("text")
     )
 )      

))

now this works fine if only box 'D' is selected, but not if (as would be normal in my problem) several boxes are selected.

in server.R something like

 if("D" %in% input$which) 

works fine but that does not seem to work in ui.R. I also tried subsetting ala R, for example

  conditionalPanel( condition = "input.items[4] == 'D'",

but that does not work either.

Wolfgang

like image 534
Wolfgang Rolke Avatar asked Feb 28 '16 21:02

Wolfgang Rolke


2 Answers

docendo gave the correct answer: the syntax is

  conditionalPanel(condition = "input.items.includes('D')"

Thanks!

like image 63
Wolfgang Rolke Avatar answered Nov 10 '22 14:11

Wolfgang Rolke


somehow it no longer works with shiny v1.1.0. I am using R version 3.5.1 with platform windows. Rather than the includes() solution, the below works well for me (just in case others encounter the same issue):

conditionalPanel(condition = "input.items.indexOf('D') > -1", ...)

like image 36
sinalpha Avatar answered Nov 10 '22 15:11

sinalpha