Column

The distribution of score by boro

Column

The number of A grade restaurants in Manhattan

The distribution of score by grade date

---
title: "NYC Restaurant Insepctions Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(p8105.datasets)
library(plotly)
```

```{r, include=FALSE}
data("rest_inspec")

plotly_box = rest_inspec %>%
  filter(
    grade == "A", boro != "Missing")

plotly_bar = rest_inspec %>% 
  filter(grade == "A", boro == "MANHATTAN", cuisine_description != "Not Listed/Not Applicable") %>% 
  count(cuisine_description) %>% 
  filter(n > 1000) %>% 
  mutate(
    cuisine_description = recode(cuisine_description, "Latin (Cuban, Dominican, Puerto Rican, South & Central American)" = "Latin")
  ) 

plotly_scatter = rest_inspec %>% 
  filter(
    boro == "MANHATTAN", str_detect(cuisine_description, "[Cc][Hh][Ii][Nn][Ee][Ss][Ee]"), grade != "Not Yet Graded") 
```


Column {data-width=650 .tabset}
-----------------------------------------------------------------------

### The distribution of score by boro

```{r}
plotly_box %>%
  mutate(
    text_label = str_c("Score: ", score)
  ) %>% 
  plot_ly(
    y = ~score, color = ~boro,
    type = "box", mode = "markers",
    alpha = .5, text = ~text_label
  ) %>% 
  layout(
    xaxis = list(title = "Boro"),
    yaxis = list(title = "Score"),
    legend = list(title = list(text = '<b> Boro </b>'), y = 0.5))

```


Column {data-width=350}
-----------------------------------------------------------------------

### The number of A grade restaurants in Manhattan

```{r}
plotly_bar %>% 
mutate(
    text_label = str_c("Number: ", n),
    cuisine_description = fct_reorder(cuisine_description, n)
  ) %>% 
  plot_ly(
    x = ~cuisine_description, y = ~n, color = ~cuisine_description,
    type = "bar", mode = "markers",
    alpha = .5, text = ~text_label
  ) %>% 
  layout(
    xaxis = list(title = "Cuisine Type"),
    yaxis = list(title = "Count"),
    legend = list(title = list(text = '<b> Cuisine Type </b>')))
```

### The distribution of score by grade date

```{r}
plotly_scatter %>% 
  mutate(
    text_label = str_c("Grade: ", grade, "\nScore: ", score)
  ) %>% 
  plot_ly(
    x = ~grade_date, y = ~score, color = ~grade,
    type = "scatter", mode = "markers",
    alpha = 1, text = ~text_label
  ) %>% 
  layout(
    xaxis = list(title = "Grade Date"),
    yaxis = list(title = "Score"),
    legend = list(title = list(text = '<b> Grade </b>'), y = 0.5))
```