title: Change graph when clicking checkbox in shiny-app
body: <pre><code>## libraries used ##
  library(shiny)
  library(shinydashboard)
  library(ggplot2)
  library(dplyr)
  
  ## dataset ##
  dates &lt;- seq.Date(as.Date("2017-01-01"), length = 1000, by = "days")
  mydata &lt;- as.data.frame(dates) %&gt;%
    mutate(satisfaction = runif(1000, 1, 100))
  
  ## ui ##
  ui &lt;- dashboardPage(
  
    dashboardHeader(disable = TRUE),
  
    dashboardSidebar(
      sidebarMenu(
        dateRangeInput("dateRange", "Please choose date", "2018-05-01", "2018-06-30"),
        checkboxInput("comparePreviousPeriod", "Compare to previous period", FALSE)
      )
    ),
  
    dashboardBody(
      fluidRow(
        box(width = 12, plotOutput("satisfactionGraph"))
      )
    )
  )
  
  server &lt;- function(input, output) {
    changing_data &lt;- reactive({
      req(input$dateRange)
      mydata[mydata$dates &gt;= input$dateRange[1] &amp; mydata$dates &lt;= input$dateRange[2],]
    })
  
    output$satisfactionGraph &lt;- renderPlot(
      ggplot(changing_data(), aes(dates, satisfaction, group = 1)) + 
        geom_line() + 
        theme_minimal() +
        xlab("Day of the year") + 
        ylab("Satisfaction level") + 
        ggtitle("User satisfaction") + 
        theme(axis.text.x = element_text(angle = 90, hjust = 1))
    )
  }
  
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>I have a shiny dashboard with a <code>checkbox</code> and a <code>dateRange</code>. Upon clicking the checkbox I want the ggplot to reveal an additional line with data from the previous period e.g If my dates are "2018-05-01" &amp; "2018-06-30" I want the new line to show data from "2018-03-01" &amp; "2018-04-31".</p>