Khám phá ẩm thực

Xây dựng ứng dụng web với Shiny trong R

Ramnath Vaidyanathan

VP of Product Research

Khám phá dữ liệu

Bảng hiển thị 10 dòng đầu từ bộ dữ liệu cuisines

Xây dựng ứng dụng web với Shiny trong R

Ảnh động xem trước ứng dụng khám phá ẩm thực

Xây dựng ứng dụng web với Shiny trong 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'))
) ) ) )
Xây dựng ứng dụng web với Shiny trong R

Ứng dụng có hộp chọn ẩm thực, thanh trượt chọn số nguyên liệu và các tab cho đầu ra

Xây dựng ứng dụng web với Shiny trong R

Thêm đầu ra: bảng tương tác

output$dt_top_ingredients <- DT::renderDT({

recipes %>%
filter(cuisine == input$cuisine) %>%
count(ingredient, name = 'nb_recipes') %>%
arrange(desc(nb_recipes)) %>%
head(input$nb_ingredients)
})
Xây dựng ứng dụng web với Shiny trong R

Tính TFIDF

Bảng hiển thị 3 nguyên liệu hàng đầu của ẩm thực Ấn Độ, dựa trên số công thức sử dụng

recipes_enriched <- recipes %>%

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

Bảng hiển thị 3 nguyên liệu hàng đầu của ẩm thực Ấn Độ, dựa trên TFIDF

Xây dựng ứng dụng web với Shiny trong R

Thêm biểu thức reactive

  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))
})
Xây dựng ứng dụng web với Shiny trong R

Thêm đầu ra: biểu đồ tương tác và đám mây từ

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)
})
Xây dựng ứng dụng web với Shiny trong R

Ảnh động xem trước ứng dụng khám phá ẩm thực

Xây dựng ứng dụng web với Shiny trong R

Hãy luyện tập!

Xây dựng ứng dụng web với Shiny trong R

Preparing Video For Download...