Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Nicolabo
Last active November 30, 2018 17:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicolabo/bef696815fd98a17fafc8f7c8830695d to your computer and use it in GitHub Desktop.
Save Nicolabo/bef696815fd98a17fafc8f7c8830695d to your computer and use it in GitHub Desktop.
Task 3
library(dplyr)
library(shiny)
library(nycflights13)
library(ggplot2)
library(ggthemes)
options(scipen = 999)
flights <- flights
airlines <- airlines
# łączenie dwóch dataframe'ów
modFlights <- flights %>%
inner_join(airlines, by = 'carrier')
# wybór siedmu linii lotniczych
chosenCarrier <- modFlights %>% count(name) %>%
arrange(desc(n)) %>%
head(7)
# filtrowanie danych
modFlights <- modFlights %>%
filter(!is.na(dep_delay), name %in% chosenCarrier$name)
shinyServer(function(input, output, session) {
output$ddelay_plot <- renderPlot({
aggDelayFlights <- modFlights %>%
group_by(hour) %>%
summarise(delayed_flight_perc = sum(dep_delay > 0) / n())
ggplot(aggDelayFlights, aes(hour, delayed_flight_perc)) +
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({
modFlights %>%
group_by(hour) %>%
summarise(delayed_flight_perc = sum(dep_delay > 0) / n()) %>%
mutate(
delayed_flight_perc = scales::percent(delayed_flight_perc)
)
})
})
fluidPage(
titlePanel(title = "Introduction to Shiny"),
sidebarPanel(
selectInput("carrierName",
label = "Select carrier:",
choices = sort(chosenCarrier$name),
selected = sort(chosenCarrier$name)[1],
multiple = T),
sliderInput('delayFlightRange',
label = "Choose minutes range of delay flights:",
min = 0, max = 1000, value = c(0, 1000), step = 5),
numericInput("distance_val", label = "Flight distance longer than (miles):", value = 500)
),
mainPanel(
tabsetPanel(
tabPanel("Delay over day",
plotOutput('ddelay_plot')
),
tabPanel("Explore data",
tableOutput("table")
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment