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.
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)
This exercise is part of the course
Building Web Applications with Shiny in R
Exercise instructions
- UI:
- Add an input in the sidebar named
cuisine
to let users select a cuisine from the full set of cuisines available in therecipes
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
.
- Add an input in the sidebar named
- 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
.
- Filter
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
ui <- fluidPage(
titlePanel('Explore Cuisines'),
sidebarLayout(
sidebarPanel(
# CODE BELOW: Add an input named "cuisine" to select a cuisine
# CODE BELOW: Add an input named "nb_ingredients" to select # of ingredients
),
mainPanel(
# CODE BELOW: Add a DT output named "dt_top_ingredients"
)
)
)
server <- function(input, output, session) {
# CODE BELOW: Render the top ingredients in a chosen cuisine as
# an interactive data table and assign it to output object `dt_top_ingredients`
}
shinyApp(ui, server)