Last active
May 26, 2018 21:00
-
-
Save Nicolabo/610d7473b40c00527bd1a292de21f5cd to your computer and use it in GitHub Desktop.
Revisions
-
Nicolabo revised this gist
May 26, 2018 . 1 changed file with 21 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,23 @@ fluidPage( titlePanel(title = "Introduction to Shiny"), sidebarPanel( selectInput("carrierName", label = "Select carrier:", choices = sort(chosenCarrier$name), selected = sort(chosenCarrier$name)[1], multiple = T), numericInput("distance_val", label = "Flight distance longer than (miles):", value = 500), uiOutput("delayRange") ), mainPanel( tabsetPanel( tabPanel("Delay over day", plotOutput('ddelay_plot') ), tabPanel("Explore data", tableOutput("table") ) ) ) ) -
Nicolabo created this gist
May 26, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ shinyServer(function(input, output, session) { output$delayRange <- renderUI({ max_delay <- max(modFlights$dep_delay) sliderInput('delayFlightRange', label = "Choose delay range (minutes):", min = 0, max = max_delay, value = c(0, max_delay), step = 10) }) dayFilteredData <- reactive({ modFlights %>% filter(name %in% input$carrierName) %>% group_by(name, hour) %>% summarise(delayed_flight_perc = sum(dep_delay > input$delayFlightRange[1] & dep_delay < input$delayFlightRange[2] & distance > input$distance_val) / sum(distance > input$distance_val)) }) output$ddelay_plot <- renderPlot({ ggplot(dayFilteredData(), aes(hour, delayed_flight_perc, fill = name)) + geom_col(position = 'dodge') + theme_hc(base_size = 18) + scale_fill_hc() + xlab("Departure hour") + ylab("Percentage of delayed flights") + scale_y_continuous(labels = scales::percent) + scale_x_continuous(limits = c(0,24), breaks = seq(0, 24, 2)) + guides(fill=guide_legend(title="")) }) output$table <- renderTable({ dayFilteredData() %>% mutate( delayed_flight_perc = scales::percent(delayed_flight_perc) ) }) }) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ shinyUI( fluidPage( titlePanel(title = "Introduction to Shiny"), sidebarPanel( selectInput("carrierName", label = "Select carrier:", choices = sort(chosenCarrier$name), selected = sort(chosenCarrier$name)[1], multiple = T), numericInput("distance_val", label = "Flight distance longer than (miles):", value = 500), uiOutput("delayRange") ), mainPanel( tabsetPanel( tabPanel("Delay over day", plotOutput('ddelay_plot') ), tabPanel("Explore data", tableOutput("table") ) ) ) ) )