요리 탐색

R로 Shiny 웹 애플리케이션 만들기

Ramnath Vaidyanathan

VP of Product Research

데이터 탐색

cuisines 데이터셋 상위 10행 표

R로 Shiny 웹 애플리케이션 만들기

explore-cuisine-app-gif.gif

R로 Shiny 웹 애플리케이션 만들기
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'))
) ) ) )
R로 Shiny 웹 애플리케이션 만들기

요리 선택 드롭다운, 재료 개수 슬라이더, 출력 탭이 있는 앱

R로 Shiny 웹 애플리케이션 만들기

출력 추가: 인터랙티브 테이블

output$dt_top_ingredients <- DT::renderDT({

recipes %>%
filter(cuisine == input$cuisine) %>%
count(ingredient, name = 'nb_recipes') %>%
arrange(desc(nb_recipes)) %>%
head(input$nb_ingredients)
})
R로 Shiny 웹 애플리케이션 만들기

TFIDF 계산

인도 요리에서 사용된 레시피 수 기준 상위 3개 재료 표

recipes_enriched <- recipes %>%

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

인도 요리에서 TFIDF 기준 상위 3개 재료 표

R로 Shiny 웹 애플리케이션 만들기

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))
})
R로 Shiny 웹 애플리케이션 만들기

출력 추가: 인터랙티브 플롯과 워드클라우드

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)
})
R로 Shiny 웹 애플리케이션 만들기

explore-cuisine-app-gif.gif

R로 Shiny 웹 애플리케이션 만들기

Vamos praticar!

R로 Shiny 웹 애플리케이션 만들기

Preparing Video For Download...