0

I have a drop down in sidebarPanel from which I can select a maximum of 2 options. I want to create an if loop where in - choosing ('Saddle Joint' and 'Gliding Joint') or ('Saddle Joint' and 'Synovial Fluid') from the drop down leads to selection of objects 'x' and 'y' in another sidebarPanel named datasets - basically creating a linkage. I tried this piece of code, but it doesn't work:

if ("Saddle Joint" %in% input$location & "Gliding Joint" %in% input$location || "Saddle Joint" %in% input$location & "Synovial Fluid" %in% input$location) {        
    updateCheckboxGroupInput(session,
                             "datasets", "Datasets:", choices = c("x","y"),
                             selected= c("x","y"))        
  }

Take a look at the screenshot! Screenshot

Thanks.

Harriss
  • 13
  • 1
  • 8

1 Answers1

0

You need to tell the server to be looking out for changes in input$location, which can be done using observeEvent, as seen here:

library(shiny)

ui <- basicPage(
  selectInput(inputId = "location",
              label = "Location",
              choices = c("Saddle Joint",
                          "Gliding Joint",
                          "Synovial Fluid",
                          "Hinge Joint",
                          "Condyloid Joint",
                          "Flexor Tenosynovium"),
              multiple = TRUE),
  checkboxGroupInput(inputId = "datasets",
                     label = "Datasets:",
                     choices = c("x", "y", "z"))
)

server <- function(input, output, session){

  observeEvent(eventExpr = input$location,
               handlerExpr = {

                 if("Saddle Joint" %in% input$location & "Gliding Joint" %in% input$location || "Saddle Joint" %in% input$location & "Synovial Fluid" %in% input$location)
                 updateCheckboxGroupInput(session = session,
                                          inputId = "datasets",
                                          selected = c("x", "y"))
               })

}

shinyApp(ui, server)
Sam Helmich
  • 949
  • 1
  • 8
  • 18