0

Assume I have a drop down in sidebarPanel - location from which I can select a maximum of 2 options. I want to create an if loop where in - chosing 'Saddle Joint' and 'Gliding Joint' from the drop down leads to selection of objects 'x' and 'y' in another sidebarPanel - datasets - basically creating a linkage.

I tried this piece of code, but it doesn't work:

if (input$location== "Saddle Joint" & input$location== "Gliding Joint") {

  updateCheckboxGroupInput(session,
                           "datasets", "Datasets:", choices = c("x","y"),
                           selected= c("x","y"))
}

Do take a look at the screenshot for better picture!

Thanks!

Screenshot

Harriss
  • 13
  • 1
  • 8
  • Well your if statement will never be true since `input$location` can't equal Saddle Joint and Gliding Joint at the same time. If `input$location` is a vector with multiple values then you want `"Saddle Joint" %in% input$location & "Glding Joint" %in% input$location` – Carl Aug 05 '16 at 17:38
  • @Carl that works! thank you! – Harriss Aug 05 '16 at 17:41
  • Ok, will submit an answer then. – Carl Aug 05 '16 at 17:43
  • @Carl if I have a vector of names, assume for example: as,ad,af.. and so on. How could I determine combinations of two (as,ad; as,af, ad,af) so that I could insert that in if loop something like, if(input$location==all combinations of the vector).. then do this – Harriss Aug 05 '16 at 17:58

1 Answers1

0

Issue was with the boolean in your if statement. Use this:

"Saddle Joint" %in% input$location & "Gliding Joint" %in% input$location

Also could use:

all(c("Saddle Joint","Gliding Joint") %in% input$location)
Carl
  • 5,569
  • 6
  • 39
  • 74