Airtravel App

Rajesh Vikraman
31st July 2017

Application Purpose

  • For showing the trend of Passenger Volumes to major international destinations from Indian Airports.

  • The user can select the Indian Airport from the dropdown menu and the number of top destinations by number of passengers to be displayed in the graph using slider bar.

  • The Application will display the trend of passenger numbers to the top destinations from Q1 2015 to Q1-2017.

  • Quarterly average of the number of passengers to all international destinations from the airport is also displayed.

Ui.R Code

library(shiny);library(plotly)
cqi <- read.csv("CQI.csv",stringsAsFactors = FALSE,   col.names = c("Year","Quarter","Foreign_City","Domestic_City","Inbound_Passengers",
 "Outbound_Passengers","Incoming_Freight","Outgoing_Freight"))
port <- cqi$Domestic_City
shinyUI(fluidPage(
    titlePanel("Passenger flow to major international destinations from Indian airports"),
 sidebarLayout( sidebarPanel(
selectInput("Airport",label = "Select Indian Airport from the list ",  choices = port,selected = 1),
sliderInput("Destnos","How many top destinations to be shown", min = 2, max=5, value = 2),
submitButton("Submit"),
h4("How to use the Application "),
div( p("Select the Indian Airport from the drop down menu.",style = "font-family: 'times'; font-si16pt"),p(" Select the number of destinations (n) using the slider bar.You can select a maximum of 5 destinations. ",style= "font-family: 'times'; font-si16pt"), style = "color:blue"),      em("Trend of Passenger flow to the top 'n' destinations will be displayed on the graph.")   ),
mainPanel(
h4("Trend of Passenger Flow to top International Destinations "),
textOutput("text"), 
plotlyOutput("travelPlot"),
 h5(em("Average Quartely Passengers to all International Destinations")),
         strong(textOutput("PassNos"))
     ))
))

Server.R Code

  library(shiny)
library(dplyr)
shinyServer(function(input, output) {
        cqi <- read.csv("CQI.csv",stringsAsFactors = FALSE, col.names = c("Year","Quarter","Foreign_City","Domestic_City","Inbound_Passengers",
          "Outbound_Passengers","Incoming_Freight","Outgoing_Freight"))
        cqi$Year<- paste(cqi$Year,cqi$Quarter);cqi <- cqi[,-2]
        totpass <- reactive({ domport<- input$Airport
cqi%>% filter(Domestic_City==domport)%>% group_by(Year)%>% summarize(Outbound_Passengers=sum(Outbound_Passengers))
        })
airtravel <- cqi %>% group_by(Domestic_City,Foreign_City) %>% summarize(Inbound_Passengers=sum(Inbound_Passengers),Outbound_Passengers=sum(Outbound_Passengers))
airtravel<- as.data.frame(airtravel)
Topdest <-  reactive({
        domport <-input$Airport;number <- input$Destnos
top_n(airtravel[airtravel$Domestic_City==domport,],number,wt=Outbound_Passengers)$Foreign_City
})         

Server.R Code Continued

toptravel <- reactive({
        Topdest<- Topdest()
        domport <-input$Airport 
        cqi[cqi$Foreign_City %in% Topdest & cqi$Domestic_City==domport,]
})
  output$travelPlot <- renderPlotly({
         topcities <- toptravel()  
    # plot quarterly graph
          plot_ly(topcities,x= ~Year,y=~Outbound_Passengers,color= ~Foreign_City,type = "scatter",mode="line")

  })
  output$text <- renderText({input$Airport})
  output$PassNos <- renderText({
          meanpass <- round(mean(as.data.frame(totpass())$Outbound_Passengers),0)
          meanpass
  })
})

Note: Since the Code recieves interactive input it's not executed. Please refer the Shiny App for execution of the code.