-
Notifications
You must be signed in to change notification settings - Fork 4
/
Bikeshare Bay Area.Rmd
118 lines (86 loc) · 2.37 KB
/
Bikeshare Bay Area.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
title: "Bikeshare Bay Area"
output: html_document
---
---
title: "Bike Shares Daily"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r global, include=FALSE}
library(flexdashboard)
library(readr)
library(leaflet)
library(DT)
library(tidyverse)
library(lubridate)
library(plotly)
trips_df <- read_csv('https://assets.datacamp.com/production/repositories/1448/datasets/1f12031000b09ad096880bceb61f6ca2fd95e2eb/sanfran_bikeshare_joined_oneday.csv') %>%
mutate(duration_min = duration_sec / 60)
```
Sidebar {.sidebar}
====================
```{r}
sliderInput("duration_slider", label = "Select maximum trip duration to display (in minutes):",
min = 0, max = 120, value = 15, step = 5, dragRange = TRUE)
sliderInput("duration_bin", label = "Select # of minutes to bin trip durations:",
min = 1, max = 15, value = 1, step = 1)
show_trips_df <- reactive({
trips_df %>%
filter(duration_sec <= input$duration_slider * 60)
})
```
Overview
====================
Column {data-width=450}
-----------------------------------------------------------------------
### Origins
```{r}
renderLeaflet({
show_trips_df() %>%
rename(latitude = start_latitude,
longitude = start_longitude) %>%
group_by(start_station_id, latitude, longitude) %>%
count() %>%
leaflet() %>%
addTiles() %>%
addCircles(radius = ~n)
})
```
Column {data-width=350}
-----------------------------------------------------------------------
### Total Trips
```{r}
renderValueBox({
valueBox(prettyNum(show_trips_df() %>%
nrow(), big.mark = ','),
icon = 'fa-bicycle')
})
```
### Trips by Start Time
```{r}
renderPlot({show_trips_df() %>%
mutate(hour = hour(start_date)) %>%
group_by(hour) %>%
summarize(`Trips Started` = n()) %>%
ggplot(aes(x = hour, y = `Trips Started`)) +
theme_bw() +
ylab('Trips Started \n') +
geom_bar(stat = 'identity')
})
```
Duration
====================
### Trip Durations
```{r}
renderPlot({show_trips_df() %>%
mutate(`Trip Duration (min)` = duration_sec / 60) %>%
ggplot(aes(x = `Trip Duration (min)`)) +
theme_bw() +
geom_histogram(binwidth = input$duration_bin) +
ylab('# Trips')
})
```