server.R

To remind you of the server.R file, and to show you which bits we have retained, let's look at the server.R file first, shown in the following code:

library(tidyverse)library(gapminder)load("geocodedData.Rdata")function(input, output) {   theData = reactive({     mapData %>%      filter(year >= input$year[1])  })   output$trend = renderPlot({    thePlot = theData() %>%    group_by(continent, year) %>%    summarise(meanLife = mean(lifeExp)) %>%    ggplot(aes(x = year, y = meanLife, group = continent,       colour = continent)) + geom_line() +       ggtitle("Graph to show life expectancy by continent over time")   if(input$linear){     thePlot = thePlot + geom_smooth(method = "lm")   }    print(thePlot)  })}

There are no surprises in this code, really; it is just a cut-down ...

Get Web Application Development with R Using Shiny - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.