14/01/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.

install.packages("opendatatoronto", 
                 repos = "http://cran.us.r-project.org",
                 dependencies = TRUE)
library(opendatatoronto)
library(tidyverse)
library(lubridate)
library(shiny)

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 server cleans up the data and calculates the difference in usage between annual pass renting versus casual pass renting.

    anni <- data2$Dur[data2$User.Type=="Annual Member"]
    cas <- data2$Dur[data2$User.Type=="Casual Member"]
    dif <- mean(anni) -mean(cas)

The server also takes the values input from the UI and applies them

        minx <- input$dur[1]
        maxx <- input$dur[2]
        ifelse(input$freq==TRUE,
               data <- data2[data2$User.Type == "Casual Member",],
               data <- data2)

Sample Output

Here is a sample plot of the data and the difference in average usage is : -18 minutes. Casual riders are more likely to travel for a longer time then frequent (annual) riders.