Column

Number of items ordered in each frozen food aisle on day 6

Column

Order hour of the day for each frozen food aisle on day 6

Count of days since prior order for each frozen food aisle on day 6

---
title: "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 instacart_data}
# loading dataset
data("instacart")

# tidying dataset 
instacart_df =
  instacart %>% 
  janitor::clean_names() %>% 
  filter(
    department %in% c("frozen"), 
    order_dow == 6
  )
```

Column {data-width=500}
-----------------------------------------------------------------------

### Number of items ordered in each frozen food aisle on day 6

```{r bar_plot}
instacart_df %>% 
  count(aisle) %>% 
  mutate(aisle = fct_reorder(aisle, n)) %>% 
  plot_ly(x = ~aisle, y = ~n, color = ~aisle, type = "bar", colors = "viridis") %>% 
  layout(xaxis = list(title = "Aisle"),
         yaxis = list(title = "Items ordered"))
```

Column {data-width=500}
-----------------------------------------------------------------------

### Order hour of the day for each frozen food aisle on day 6

```{r box_plot}
instacart_df %>% 
  mutate(aisle = fct_reorder(aisle, order_hour_of_day)) %>% 
  plot_ly(y = ~order_hour_of_day, color = ~aisle, type = "box", colors = "viridis") %>% 
  layout(xaxis = list(title = "Aisle"),
         yaxis = list(title = "Order hour of the day"))
```

### Count of days since prior order for each frozen food aisle on day 6

```{r histogram}
instacart_df %>% 
  plot_ly(x = ~days_since_prior_order, color = ~aisle, type = "histogram", colors = "viridis") %>% 
  layout(xaxis = list(title = "Days since prior order"),
         yaxis = list(title = "Count"))
```