Explore cuisines

Building Web Applications with Shiny in R

Ramnath Vaidyanathan

VP of Product Research

Explore data

A table displaying top 10 rows from the cuisines dataset

Building Web Applications with Shiny in R

explore-cuisine-app-gif.gif

Building Web Applications with Shiny in R
ui <- fluidPage(
  titlePanel('Explore Cuisines'),
  sidebarLayout(
    sidebarPanel(

selectInput('cuisine', 'Select Cuisine', unique(recipes$cuisine)),
sliderInput('nb_ingredients', 'Select No. of Ingredients', 5, 100, 20),
), mainPanel( tabsetPanel(
tabPanel('Word Cloud', d3wordcloudOutput('wc_ingredients')),
tabPanel('Plot', plotly::plotlyOutput('plot_top_ingredients')),
tabPanel('Table', DT::DTOutput('dt_top_ingredients'))
) ) ) )
Building Web Applications with Shiny in R

An app displaying a drop down to select cuisine an a slider to select number of ingredients, along with tabs for the outputs

Building Web Applications with Shiny in R

Add output: interactive table

output$dt_top_ingredients <- DT::renderDT({

recipes %>%
filter(cuisine == input$cuisine) %>%
count(ingredient, name = 'nb_recipes') %>%
arrange(desc(nb_recipes)) %>%
head(input$nb_ingredients)
})
Building Web Applications with Shiny in R

Compute TFIDF

A table displaying top 3 ingredients of Indian cuisine, based of number of recipes in which they are used

recipes_enriched <- recipes %>%

count(cuisine, ingredient, name = 'nb_recipes') %>%
tidytext::bind_tf_idf(ingredient, cuisine, nb_recipes)

A table displaying top 3 ingredients of Indian cuisine, based of TFIDF

Building Web Applications with Shiny in R

Add a reactive expression

  rval_top_ingredients <- reactive({

recipes_enriched %>%
filter(cuisine == input$cuisine) %>%
arrange(desc(tf_idf)) %>%
head(input$nb_ingredients) %>%
mutate(ingredient = forcats::fct_reorder(ingredient, tf_idf))
})
Building Web Applications with Shiny in R

Add outputs: interactive plot and word cloud

output$plot_top_ingredients <- plotly::renderPlotly({
  rval_top_ingredients() %>%
    ggplot(aes(x = ingredient, y = tf_idf)) +
    geom_col() +
    coord_flip()
})
output$wc_ingredients <- d3wordcloud::renderD3wordcloud({
  d <- rval_top_ingredients()
  d3wordcloud(d$ingredient, d$nb_recipes, tooltip = TRUE)
})
Building Web Applications with Shiny in R

explore-cuisine-app-gif.gif

Building Web Applications with Shiny in R

Let's practice!

Building Web Applications with Shiny in R

Preparing Video For Download...