├── README.md ├── server.r └── ui.r /README.md: -------------------------------------------------------------------------------- 1 | ShinyTimeseriesForecasting 2 | ========================== 3 | 4 | Timeseries Forecasting with R, the Forecast R package and Shiny. 5 | 6 | 7 | -------------------------------------------------------------------------------- /server.r: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | library(datasets) 3 | library(forecast) 4 | 5 | shinyServer(function(input, output) { 6 | 7 | getDataset <- reactive({ 8 | if (input$variable=="AirPassengers") 9 | { 10 | return(AirPassengers) 11 | } 12 | else if (input$variable=="gas") 13 | { 14 | return(gas) 15 | } 16 | else 17 | { 18 | return(wineind) 19 | } 20 | }) 21 | 22 | output$caption <- renderText({ 23 | paste("Dataset: ", input$variable) 24 | }) 25 | 26 | output$dcompPlot <- renderPlot({ 27 | ds_ts <- ts(getDataset(), frequency=12) 28 | f <- decompose(ds_ts) 29 | plot(f) 30 | }) 31 | 32 | output$arimaForecastPlot <- renderPlot({ 33 | fit <- auto.arima(getDataset()) 34 | plot(forecast(fit, h=input$ahead)) 35 | }) 36 | 37 | output$etsForecastPlot <- renderPlot({ 38 | fit <- ets(getDataset()) 39 | plot(forecast(fit, h=input$ahead)) 40 | }) 41 | 42 | }) 43 | -------------------------------------------------------------------------------- /ui.r: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | 3 | # Define UI 4 | shinyUI(pageWithSidebar( 5 | 6 | # Application title 7 | headerPanel("Timeseries Forecasting"), 8 | 9 | # Sidebar with controls to select the dataset and forecast ahead duration 10 | sidebarPanel( 11 | selectInput("variable", "Variable:", 12 | list("Air Passengers" = "AirPassengers", 13 | "Australian total wine sales" = "wineind", 14 | "Australian monthly gas production" = "gas")), 15 | numericInput("ahead", "Months to Forecast Ahead:", 12), 16 | 17 | submitButton("Update View") 18 | ), 19 | 20 | 21 | 22 | # Show the caption and forecast plots 23 | mainPanel( 24 | h3(textOutput("caption")), 25 | 26 | tabsetPanel( 27 | tabPanel("Exponetial Smoothing (ETS) Forecast", plotOutput("etsForecastPlot")), 28 | tabPanel("Arima Forecast", plotOutput("arimaForecastPlot")), 29 | tabPanel("Timeseries Decomposition", plotOutput("dcompPlot")) 30 | ) 31 | ) 32 | )) 33 | --------------------------------------------------------------------------------