---
title: "NYC Restaurant Inspections Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(tidyverse)
library(p8105.datasets)
library(flexdashboard)
library(plotly)
library(httr)
library(jsonlite)
```
```{r, include = FALSE}
data("rest_inspec")
rest_inspec %>%
group_by(boro, grade) %>%
summarize(n = n()) %>%
pivot_wider(names_from = grade, values_from = n)
rest_inspec =
rest_inspec %>%
filter(grade %in% c("A", "B", "C"), boro != "Missing") %>%
mutate(boro = str_to_title(boro)) %>% view
# to determine restaurants with most data points
rest_inspec %>%
group_by(camis) %>%
summarize(Count = n()) %>%
arrange(desc(Count))
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
rest_inspec %>%
filter(boro == "Manhattan", cuisine_description == "Ice Cream, Gelato, Yogurt, Ices") %>%
plot_ly(x = ~dba, y = ~grade, type = "scatter", mode = "markers", color = ~grade, alpha = .5) %>%
layout(
title = 'Inspection Grades of Manhattan Ice Cream Shops Over Time',
xaxis = list(title = 'Restaurant Name'),
yaxis = list(title = 'Inspection Grade')
)
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
span_bar = rest_inspec %>%
filter(str_detect(cuisine_description, "Spanish")) %>%
mutate(boro = fct_infreq(boro)) %>%
ggplot(aes(x = boro, fill = grade)) +
geom_bar() +
labs(
title = "Inspection Grades of Spanish Restaurants in NYC",
x = "Boro",
y = "Number of Restaurants"
)
ggplotly(span_bar)
```
### Chart C
```{r}
rest_inspec %>%
filter(camis == 40370167) %>%
mutate(
text_label = str_c("violation info: ", violation_description)
) %>%
plot_ly(x = ~inspection_date, y = ~grade, type = "scatter", mode = "line", alpha = .5, color = ~critical_flag, text = ~text_label) %>%
layout(
title = "Inspection Grades of Burger King (Northern Blvd, Queens)",
xaxis = list(title = 'Inspection Date'),
yaxis = list(title = 'Inspection Grade')
)
```