Column

Chart A

Column

Chart B

Chart C

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

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

```{r}
data(ny_noaa)

ny_noaa = 
  ny_noaa %>% 
  filter(!is.na(prcp) & !is.na(snow) &
           !is.na(snwd) & !is.na(tmax) & !is.na(tmin)) %>% 
  filter(date > as.Date('2010-09-01'))
```


Column {data-width=600}
-----------------------------------------------------------------------

### Chart A

```{r}
ny_noaa %>% 
  mutate(
    text_label = str_c("Date: ", date, "\nSnow depth (mm): ", snwd)
  ) %>% 
  plot_ly(
    x = ~prcp, y = ~snow, color = ~snwd, text = ~text_label,
    type = "scatter", mode = "markers", alpha = 0.5
  ) %>%
  layout(
    title = "Trends Between Precipitation and Snowfall from Sept 2010 to Dec 2010", 
    xaxis = list(title = "Precipitation (tenths of mm)"), 
    yaxis = list(title = " Snowfall (mm)"),
    colorbar = list(title = "Snow Depth (mm)")
  )
```

Column {data-width=400}
-----------------------------------------------------------------------

### Chart B

```{r}
ny_noaa %>% 
  mutate(
    month = format(date, "%m")
  ) %>% 
  plot_ly(
    x = ~month, y = ~prcp,
    type = "box", color = "viridis"
  ) %>%
  layout(
    title = "Average Precipitation by Month from Sept 2010 to Dec 2010",
    xaxis = list(title = "Month"),
    yaxis = list(title = "Precipitation (tenths of mm)")
  )
```

### Chart C

```{r}
ny_noaa_summary <- ny_noaa %>%
  mutate(
    month = format(date, "%m"),
    tmax = as.numeric(tmax),
    tmin = as.numeric(tmin),
    tep_range = tmax - tmin
  )

ny_noaa_summary = ny_noaa_summary %>% 
  group_by(month) %>% 
  summarize(avg_tep_range = mean(tep_range, na.rm = TRUE))

ny_noaa_summary %>% 
  plot_ly(
    x = ~month, y = ~avg_tep_range,
    type = "bar"
  ) %>%
  layout(
    title = "Average Temperature Range by Month from Sept 2010 to Dec 2010",
    xaxis = list(title = "Month"),
    yaxis = list(title = "Average Temperature Range")
  )
```