How to prevent shiny plot from being redrawn multiple times per UI interaction?

Viewed 780

In my shiny app I have a date range input and a group of checkboxes. The checkbox choices are determined based on the input$dateRange. I'm running into an issue where the plot is being redrawn twice every time the date range is changed. The first time it is redrawn it will use the new date ranges, but the old checkbox choices. Then the checkbox choices are updated and the plot is redrawn a second time.

Is there any way to prevent redrawing the plot multiple times and only have it drawn once all the other UI elements have updated?

server.R code snippet

  # Check boxes for variants in run
  output$choose_variants <- renderUI({
    # Get the variants associated with the run
    dat <- loadVariants(input$dateRange[1], input$dateRange[2])
    if(is.null(dat))
      return()

    # Create the checkboxes and select them all by default
    checkboxGroupInput("variants", "Variants",
                        choices  = dat$variant,
                        selected = dat$variant)
  })

  # Output the data
  output$plot1 <- renderPlot({
    runLocations <- loadRunsBetweenDates(input$dateRange[1], input$dateRange[2], input$variants)
    #ggplot()
  })

ui.R code snippet

  sidebarPanel(
    dateRangeInput('dateRange',
      label = 'Date range',
      start = Sys.Date(), end = Sys.Date()
    ),
    uiOutput("choose_variants")
  ),
1 Answers
Related