Aan de slagGa gratis aan de slag

More exploration of the Gapminder data

To use the gapminder data in a Shiny app, you will often have to filter the dataset in order to retain only a subset of the rows. You can use the subset() function for that.

Deze oefening maakt deel uit van de cursus

Case Studies: Building Web Applications with Shiny in R

Cursus bekijken

Oefeninstructies

You are given a Shiny app that contains an empty text output. Your task is to:

  • Load the gapminder package.
  • Determine the population of France in year 1972 using the subset() function, and display that number in the text output (line 14).

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Load the gapminder package
___

# Define UI for the application
ui <- fluidPage(
  "The population of France in 1972 was",
  textOutput("answer")
)

# Define the server function
server <- function(input, output) {
  output$answer <- renderText({
    # Determine the population of France in year 1972
    subset(___ & ___)$___
  })
}

# Run the application
shinyApp(ui = ui, server = server)
Code bewerken en uitvoeren