What Does it Do?

The app uses data available at

Touring Plans Blog

The app:

  • Extracts the data corresponding to the user’s selection of visit month, weekday/weekend, and ride.
  • Creates a box plot of all posted wait times for the selection
  • Creates a smoothed prediction curve (loess) from the selected data
  • Plots are converted to plotly for interactivity

Result: A shiny app that is fun to play around with!

Title page photo by Matt Stroshane

Example

Suppose we are interested in riding Flight of Passage on a weekday in March. Here are the data that would be extracted: (Code is executed here but shown later.)

## # A tibble: 1,240 x 7
##    date       datetime            SACTMIN WaitTime Month   Day  Time
##    <chr>      <dttm>                <int>    <int> <dbl> <dbl> <dbl>
##  1 03/05/2018 2018-03-05 06:52:07      NA       60     3     2   652
##  2 03/05/2018 2018-03-05 06:59:06      NA       60     3     2   659
##  3 03/05/2018 2018-03-05 07:03:06      NA       90     3     2   703
##  4 03/05/2018 2018-03-05 07:04:15      NA       90     3     2   704
##  5 03/05/2018 2018-03-05 07:10:08      NA      120     3     2   710
##  6 03/05/2018 2018-03-05 07:15:05      NA      150     3     2   715
##  7 03/05/2018 2018-03-05 07:17:06      NA      150     3     2   717
##  8 03/05/2018 2018-03-05 07:24:07      NA      180     3     2   724
##  9 03/05/2018 2018-03-05 07:26:59      NA      180     3     2   726
## 10 03/05/2018 2018-03-05 07:30:09      NA      180     3     2   730
## # … with 1,230 more rows

The Server Function

shinyServer(function(input, output) {
    Data1 <- reactive({
        RideInd <- which.max(RideSelect == input$Ride)
        MonthInd <- which.max(month.name == input$MonthIn)
        DataList[[RideInd]] %>% filter(Month == MonthInd) %>% 
            filter(Day %in% ifelse(input$WeekEndIn,WeekEnd,WeekDay)) %>%
            filter(Time > 500) %>% rename(WaitTime=SPOSTMIN)
    })
    g1 <- reactive({
        ggplot(Data1())+geom_boxplot(aes(y=WaitTime))+theme_bw()+
              labs(y="Posted Wait (minutes)")+
                theme(axis.text.x=element_blank(),
                     axis.ticks.x=element_blank())
    })

Shiny Server Part 2

    output$BoxPlot <- renderPlotly(
        ggplotly(g1())
    )
    g2 <- reactive({
        ggplot(Data1())+geom_smooth(aes(x=Time,
          y=WaitTime),method="loess",
          formula=y ~ x,se=FALSE)+theme_bw()+
            labs(x="Time (24 hr)",y="Predicted Wait (minutes)")+
              scale_x_continuous(breaks=seq(500,2400,by=100))+
            theme(axis.text.x = element_text(angle = 45, hjust = 1))
    })
    output$CurvePlot <- renderPlotly(
        ggplotly(g2())
    )

})

To see the app in action, click the link!