title: Using a Shiny slider to control output on a ggplot
body: <p>I am a complete novice with R and Shiny.</p>
  
  <p>I have been trying to develop a tool to explore economic data. I am using GDP index data. So far the tool allows you to load different sectors but I would like to control for years as well. Here is what the <a href="https://i.stack.imgur.com/ccizS.png" rel="nofollow noreferrer">GDP Tool</a> looks like at the moment.</p>
  
  <p>I want to use the slider to control the years as they appear on the plot.</p>
  
  <p>This is the code I have so far:</p>
  
  <pre><code>library(shiny)
  library(ggplot2)
  GDPData = read.csv("Data/GDP_Data_New.csv", stringsAsFactors = FALSE)
  
  ui &lt;- fluidPage(
    sidebarPanel(
      tags$h1("Scottish GDP by Sector")
  
    ),
    mainPanel(
      tabsetPanel(
        tabPanel("Broad Sectors", 
                 plotOutput("Highlevel"),
                 sliderInput("SectorTime", "Select a time period", min = 1998, max = 2016,
                             value = c(1998,2016)),
                 checkboxGroupInput("Indicator","Select an indicator:",   
                                    c("Total" = "Total ", "Production" = "Production", "Construction" = "Construction","Services" = "Services", "Agriculture, forestry and fishing" = "AFF"),
                                    selected = "Total ")),
        tabPanel("Production", 
                 plotOutput("Production"),
                 checkboxGroupInput("ProductionIndicator","Select an indicator:",   
                                    c("Total" = "Production", "Manufacturing" = "Manufacturing", "Mining and Quarrying" = "Mning","Electricity &amp; Gas Supply" = "Electricty", "Water Supply &amp; Waste Management" = "WaterWaste"),
                                    selected = "Production")),
        tabPanel("Services",
                 plotOutput("Services"),
                 checkboxGroupInput("ServicesIndicator","Select an indicator:",   
                                    c("Total" = "Services", "Distribution, Hotels and Catering" = "Distribution","Transport, Storage and Communication" = "Transport", "Business Services and Finance" = "Professional","Government, and Other Services" = "Public"),
                                    selected = "Services"))
                 )
  
      )
  )
  
  server &lt;- function(input, output, session) {
  
    SectorsData=reactive({
      return(GDPData[GDPData$Sector%in%input$Indicator,])
      })
    ProductionData=reactive({
      return(GDPData[GDPData$Sector%in%input$ProductionIndicator,])
    })
    ServicesData=reactive({
      return(GDPData[GDPData$Sector%in%input$ServicesIndicator,])
    })
  
    output$Highlevel &lt;- renderPlot(ggplot(SectorsData(), aes(x=Year, y=Index, group=Sector, colour=Sector)) + geom_line()+geom_point()+theme_minimal())
    output$Production &lt;- renderPlot(ggplot(ProductionData(), aes(x=Year, y=Index, group=Sector, colour=Sector)) + geom_line()+geom_point()+theme_minimal())
    output$Services &lt;- renderPlot(ggplot(ServicesData(), aes(x=Year, y=Index, group=Sector, colour=Sector)) + geom_line()+geom_point()+theme_minimal())
  }
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>The CSV file has three columns "Sector","Year","Index"</p>
  
  <p>Any help would be greatly appreciated.</p>