install.packages("opendatatoronto",
repos = "https://cran.us.r-project.org",
dependencies = TRUE)
library(opendatatoronto)
library(tidyverse)
library(lubridate)
library(shiny)
Bike shares in Toronto
Project
Shiny App
R
Analysis of a bike sharing app in Toronto
Photo by Maarten van den Heuvel on Unsplash
This article is based on a project written on 01/14/2021
Bike Rental Shiny App
This application use the data collected from the Toronto Open Data to generate a histogram of the usage of rental bikes in Toronto during the month of June in 2020.
UI
There are two user inputs on the UI side:
A slider that limits the maximum and minimum of the displayed values
A checkbox that excludes users with a annual bike pass
sidebarPanel(
sliderInput("dur",
"Trip Duration:",
min = 0,
max = 500,
value = c(0,500)),
checkboxInput("freq",
"Exclude annual users:",
value = FALSE))
Server
The following code is used for the server side logic, this includes downloading the data from the ‘opendatatoronto’ library.
# get package
<- show_package("7e876c24-177c-4605-9cef-e50dd74c617f")
package
# get all resources for this package
<- list_package_resources("7e876c24-177c-4605-9cef-e50dd74c617f")
resources # identify datastore resources; by default, Toronto Open Data sets datastore resource format to CSV for non-geospatial and GeoJSON for geospatial resources
<- filter(resources, tolower(format) %in% c('zip', 'geojson'))
datastore_resources # load the first datastore resource as a sample
<- filter(datastore_resources, name == "Bike share ridership 2020") %>% get_resource()
data <- data$`2020-06.csv`
data2 grepl("Time",names(data2))] <-
data2[lapply(data2[grepl("Time",names(data2))], parse_date_time, orders = "mdy HM")
$Dur <- as.numeric(data2$End.Time - data2$Start.Time,units="mins") data2
Application
The final application takes a while to load as the data needs to be downloaded and sorted through. In future iterations, I would save the data locally as an RDS file.