Exercise

Explore cuisines: top ingredients

Food has universal appeal, and the amazing array of dishes one can concoct with the multitude of ingredients leads to near infinite variety! In this exercise, you will use a dataset named recipes that contains recipes, the cuisine it belongs to, and the ingredients it uses, to build a Shiny app that lets the user explore the most used ingredients by cuisine.

Your final app should resemble the image in this screenshot.

An app displaying an interactive table of top ingredients by chosen cuisine

We have already loaded the packages shiny and dplyr, as well as the dataset recipes. Additionally, here is a handy snippet of code that gets you the top 10 ingredients used in Greek cuisine. You will find this useful to create the interactive data table in the app based on the cuisine and number of ingredients selected by the user.

recipes %>% 
  filter(cuisine == 'greek') %>% 
  count(ingredient, name = 'nb_recipes') %>% 
  arrange(desc(nb_recipes)) %>% 
  head(10)

Instructions

100 XP
  • UI:
    • Add an input in the sidebar named cuisine to let users select a cuisine from the full set of cuisines available in the recipes dataset.
    • Add a slider input named nb_ingredients in the sidebar to let users select the number of ingredients to display.
    • Add an interactive data table output in the main panel named dt_top_ingredients.
  • Server:
    • Filter recipes based on the selected cuisine and number of top ingredients to display.
    • Render the filtered data as an interactive data table.
    • Assign it to an output object named dt_top_ingredients.