1. Learn
  2. /
  3. Courses
  4. /
  5. Building Web Applications with Shiny in R

Exercise

Add a select input

Adding an input to a shiny app is a two step process, where you first add an ___Input(“x”) function to the UI and then access its value in the server using input$x.

For example, if you want users to choose an animal from a list, you can use a selectInput, and refer to the chosen value as input$animal:

selectInput(
  'animal', 
  'Select Animal', 
  selected = 'Cat', 
  choices = c('Dog', 'Cat')
)

In this exercise, you will build a Shiny app that lets users visualize the top 10 most popular names by sex by adding an input to let them choose the sex.

Instructions

100 XP
  • Add a select input named "sex" to let users choose between "M" and "F", with a default of "F".
  • Update server code to get the top 10 names for the chosen sex instead of "F" only.