Column

Chart A

Column

Chart B

Chart C

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
editor_options: 
  chunk_output_type: console
---

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

```{r}
data("instacart")
```

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

### Chart A

```{r}
yax_title = list(title = "Number of Purchases")
xax_title = list(title = "Types of Snacks")

snack_bar = 
  instacart %>%  
  filter(department == "snacks") %>% 
  count(aisle) %>% 
  mutate(
    aisle = fct_reorder(aisle, n)
    ) %>% 
  plot_ly(x = ~aisle, y = ~n, color = ~aisle, colors = "viridis", type = "bar") %>% 
  layout(yaxis = yax_title, xaxis = xax_title)

snack_bar
```

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

### Chart B

```{r}
yord_title = list(title = "Order Number")
xord_title = list(title = "Days Since Prior Order")

pet_time = 
  instacart %>% 
  filter(department == "pets") %>%
  plot_ly(x = ~days_since_prior_order, y = ~order_number, 
          color = ~aisle, colors = "viridis", type = "scatter", symbol = ~aisle) %>% 
  layout(yaxis = yord_title, xaxis = xord_title) 

pet_time
```

### Chart C

```{r}
y_title = list(title = "Number of Snack Orders")
x_title = list(title = "Hour of the Day (Military Time)")

snack_hour = 
  instacart %>% 
  filter(department == "snacks") %>% 
  group_by(order_hour_of_day) %>%
  plot_ly(
    x = ~order_hour_of_day, 
    colors = "viridis", 
    type = "histogram"
    ) %>% 
   layout(yaxis = y_title, xaxis = x_title)

snack_hour
```