Skip to content

Instantly share code, notes, and snippets.

@Nicolabo
Created May 26, 2018 19:29
Show Gist options
  • Save Nicolabo/eedba90a39881e173550a5ccead1b723 to your computer and use it in GitHub Desktop.
Save Nicolabo/eedba90a39881e173550a5ccead1b723 to your computer and use it in GitHub Desktop.
Task 4
shinyServer(function(input, output, session) {
output$ddelay_plot <- renderPlot({
aggDelayFlights <- 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))
ggplot(aggDelayFlights, 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({
aggDelayFlights <- 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))
aggDelayFlights %>%
mutate(
delayed_flight_perc = scales::percent(delayed_flight_perc)
)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment