Git Product home page Git Product logo

ha-shiny-flights's Introduction

HA-Shiny-Flights

############################ ui.R ##############################

This is the user-interface definition of a Shiny web application.

You can find out more about building applications with Shiny here:

library(shiny) library(ggplot2) library(nycflights13) library(data.table)

todat <- function(a,b,c) {paste(a,sprintf('%02d',b),sprintf('%02d',c),sep='/')}

shinyUI(fluidPage(

Application title

titlePanel("Old Faithful Geyser Data"),

Sidebar with a slider input for number of bins

sidebarLayout( sidebarPanel( sliderInput('dist','max distance', min = min(flights$distance), max = max(flights$distance), value = c(min(flights$distance),min(flights$distance)+300) ), selectInput('grp', 'group by', choices = c("origin","dest","carrier") ),

  selectInput('ddate1', 'dep date from', 
               choices = sort(unique(todat(flights$year,flights$month,flights$day)))
             ),
  selectInput('ddate2', 'dep date to', 
               choices = sort(unique(todat(flights$year,flights$month,flights$day)))
             )
  
),
# Show a plot of the generated distribution
mainPanel(
  tabsetPanel(
    tabPanel('Some statistics', dataTableOutput('tab1')),
    tabPanel('Distance stat', plotOutput("dist")),
    tabPanel('Air time stat', plotOutput("airt")),
    tabPanel('Dealy stat', plotOutput("dela")),
    tabPanel('Selected rows', dataTableOutput('tab2'))
  )
)

) ))

############################ server.R ##############################

This is the server logic for a Shiny web application.

You can find out more about building applications with Shiny here:

library(shiny) library(data.table)

todat <- function(a,b,c) {paste(a,sprintf('%02d',b),sprintf('%02d',c),sep='/')} f <- flights f$dep_date <- todat(flights$year,flights$month,flights$day) setDT(f) f[, arr_time := paste(substr(sprintf('%04d',f$arr_time), 1, 2),substr(sprintf('%04d',f$arr_time), 3, 4),sep = ':')] f[, dep_time := paste(sprintf('%02d',f$hour),sprintf('%02d',f$minute),sep = ':')]

shinyServer(function(input, output) {

fl <- reactive({ f[dep_date >= input$ddate1 & dep_date <= input$ddate2 & distance >= input$dist[1] & distance <= input$dist[2], .(dep_date, dep_time, dep_delay, arr_time, arr_delay, carrier, tailnum, flight, origin, dest, air_time, distance )] })

output$dist <- renderPlot({ #ggplot(fl(), aes(fl()[,input$grp], distance)) + geom_boxplot() ggplot(fl(), aes(origin, distance)) + geom_boxplot() }) output$airt <- renderPlot({ ggplot(fl(), aes(origin, air_time)) + geom_boxplot() }) output$dela <- renderPlot({ ggplot(fl(), aes(origin, arr_delay)) + geom_boxplot() })

output$tab1 <- renderDataTable({ fl()[, .("flights no" = .N, "avg distance" = mean(distance, na.rm = TRUE), "avg air time" = mean(air_time, na.rm = TRUE), "avg delay" = mean(arr_delay, na.rm = TRUE), "max delay" = max(arr_delay, na.rm = TRUE) ), by = eval(input$grp)] })

output$tab2 <- renderDataTable({ fl()[,] })

})

ha-shiny-flights's People

Contributors

xcabbage avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.