Session Ready
Exercise

App 2: Popular Baby Names

Building a Shiny app is a modular process. You start with the UI, then you work on the server code, building outputs based on the user inputs. The more you practice this approach deliberately, the easier it will become to build good apps.

You will now build a Shiny app that lets a user choose sex and year, and will display the top 10 most popular names in that year as a column plot of proportion of births (prop) by name (name). Your final app should visually resemble the screenshot below.

An app where the name selector and year slider appear in the left sidebar, while the graph appears on the right in the main panel

We have provided a function get_top_names() to extract the top 10 names for a given year and sex. For example, you can get the top 10 male names for the year 2000 using get_top_names(2000, "M").

We have also loaded the ggplot2 package. You can create a column plot from a data frame d with columns x and y using:

ggplot(d, aes(x = x, y = y)) +
  geom_col()
Instructions
100 XP
  • Add an input to let the user select sex (M / F).
  • Add a slider to let the user select a year (1880 to 2017).
  • Build the UI layout keeping the inputs in the sidebar, outputs on the right, and a title on the top.
  • Add an output to the server to render a column plot based on year and sex. Note that you can add multiple lines of code inside the curly braces of a rendering function function: render***({___}).