---
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)
data("instacart")
```
```{r}
instacart =
instacart %>%
mutate(
day = order_dow +1,
day_of_week = lubridate::wday(day, label = TRUE, locale = "English_United States")
) %>%
select(order_id, product_id, order_number, day_of_week, order_hour_of_day, product_name, aisle, department) %>%
drop_na()
```
Column {data-width=600}
-----------------------------------------------------------------------
### Chart A
```{r}
instacart %>%
count(order_hour_of_day, department) %>%
plot_ly(
x = ~order_hour_of_day, y = ~n, type = "scatter", mode = "lines", color = ~department, colors = "viridis"
)%>%
layout(title = "Number of Orders during the day")
```
Column {data-width=400}
-----------------------------------------------------------------------
### Chart B
```{r}
instacart %>%
sample_n(4000) %>%
plot_ly(
y = ~order_number, color = ~day_of_week, type = "box", colors = "viridis"
)%>%
layout(title = "Order number distribution during the week")
```
### Chart C
```{r}
instacart %>%
group_by(aisle) %>%
summarise(num_order = n()) %>%
filter(num_order > 20000) %>%
mutate(aisle = reorder(aisle, num_order)) %>%
plot_ly(
x = ~aisle, y = ~num_order, color = ~aisle, type = "bar", colors = "viridis"
) %>%
layout(title = "Number of orders of different aisles")
```