It is showing error: series is not periodic or has less than two periods
I think it might be bcoz of the same year continuity in the data.I am not sure. if it is the case then please let me know how to rectify it.
library(plotly)
#> Loading required package: ggplot2
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
library(shinydashboard)
#>
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>
#> box
library(shinycssloaders)
library(tidyverse)
library(readr)
library(shiny)
library(dplyr)
library(DT)
#>
#> Attaching package: 'DT'
#> The following objects are masked from 'package:shiny':
#>
#> dataTableOutput, renderDataTable
library(tidyr)
library(shinycustomloader)
library(leaflet)
library(leaflet.extras)
library(htmltools)
library(forecast)
library(tseries)
library(dygraphs)
ui<-fluidPage(
fluidPage(
mainPanel(width=10,withLoader(dygraphOutput("forecast",height = 650),type = "html",loader = "loader9"))
)
)
server<-function(input,output,session){
output$forecast <- renderDygraph({
d1<-tibble::tribble(
~Unitname, ~AbortionCount, ~Month,
"a", 176, "Jan-19",
"b", 254, "Jan-19",
"c", 279, "Jan-19",
"d", 263, "Jan-19",
"e", 452, "Jan-19",
"f", 124, "Jan-19",
"g", 463, "Jan-19",
"h", 785, "Jan-19",
"i", 254, "Jan-19",
"j", 163, "Jan-19",
"k", 245, "Jan-19",
"l", 415, "Jan-19",
"m", 632, "Jan-19",
"n", 179, "Jan-19",
"o", 197, "Jan-19",
"p", 141, "Jan-19",
"q", 421, "Jan-19",
"r", 152, "Jan-19",
"s", 365, "Jan-19",
"t", 452, "Jan-19",
"u", 635, "Jan-19",
"v", 214, "Jan-19",
"w", 125, "Jan-19",
"x", 208, "Jan-19",
"y", 92, "Jan-19",
"z", 270, "Jan-19",
"aa", 132, "Jan-19",
"bb", 46, "Jan-19",
"cc", 160, "Jan-19",
"dd", 106, "Jan-19",
"ee", 241, "Jan-19",
"ff", 189, "Jan-19",
"gg", 135, "Jan-19",
"hh", 451, "Jan-19",
"a", 163, "Feb-19",
"b", 215, "Feb-19",
"c", 263, "Feb-19",
"d", 103, "Feb-19",
"e", 169, "Feb-19",
"f", 145, "Feb-19",
"g", 212, "Feb-19",
"h", 108, "Feb-19",
"i", 57, "Feb-19",
"j", 200, "Feb-19",
"k", 138, "Feb-19",
"l", 92, "Feb-19",
"m", 221, "Feb-19",
"n", 165, "Feb-19",
"o", 156, "Feb-19",
"p", 140, "Feb-19",
"q", 167, "Feb-19",
"r", 77, "Feb-19",
"s", 17, "Feb-19",
"t", 95, "Feb-19",
"u", 146, "Feb-19",
"v", 167, "Feb-19",
"w", 117, "Feb-19",
"x", 172, "Feb-19",
"y", 71, "Feb-19",
"z", 247, "Feb-19",
"aa", 129, "Feb-19",
"bb", 43, "Feb-19",
"cc", 163, "Feb-19",
"dd", 91, "Feb-19",
"ee", 242, "Feb-19",
"ff", 158, "Feb-19",
"gg", 109, "Feb-19",
"hh", 333, "Feb-19",
"a", 182, "Mar-19",
"b", 189, "Mar-19",
"c", 241, "Mar-19",
"d", 127, "Mar-19",
"e", 174, "Mar-19",
"f", 135, "Mar-19",
"g", 274, "Mar-19",
"h", 106, "Mar-19",
"i", 73, "Mar-19",
"j", 192, "Mar-19",
"k", 143, "Mar-19",
"l", 109, "Mar-19",
"m", 210, "Mar-19",
"n", 157, "Mar-19",
"o", 170, "Mar-19",
"p", 134, "Mar-19",
"q", 183, "Mar-19",
"r", 98, "Mar-19",
"s", 22, "Mar-19",
"t", 74, "Mar-19",
"u", 148, "Mar-19",
"v", 220, "Mar-19",
"w", 94, "Mar-19",
"x", 152, "Mar-19",
"y", 92, "Mar-19",
"z", 240, "Mar-19",
"aa", 112, "Mar-19",
"bb", 33, "Mar-19",
"cc", 146, "Mar-19",
"dd", 96, "Mar-19",
"ee", 247, "Mar-19",
"ff", 155, "Mar-19",
"gg", 140, "Mar-19",
"hh", 383, "Mar-19",
"a", 169, "Apr-19",
"b", 214, "Apr-19",
"c", 209, "Apr-19",
"d", 103, "Apr-19",
"e", 169, "Apr-19",
"f", 126, "Apr-19",
"g", 236, "Apr-19",
"h", 91, "Apr-19",
"i", 97, "Apr-19",
"j", 179, "Apr-19",
"k", 122, "Apr-19",
"l", 109, "Apr-19",
"m", 181, "Apr-19",
"n", 149, "Apr-19",
"o", 184, "Apr-19",
"p", 138, "Apr-19",
"q", 189, "Apr-19",
"r", 113, "Apr-19",
"s", 21, "Apr-19",
"t", 92, "Apr-19",
"u", 149, "Apr-19",
"v", 183, "Apr-19",
"w", 108, "Apr-19",
"x", 141, "Apr-19",
"y", 104, "Apr-19",
"z", 255, "Apr-19",
"aa", 108, "Apr-19",
"bb", 31, "Apr-19",
"cc", 145, "Apr-19",
"dd", 79, "Apr-19",
"ee", 237, "Apr-19",
"ff", 121, "Apr-19",
"gg", 131, "Apr-19",
"hh", 309, "Apr-19",
"a", 185, "May-19",
"b", 222, "May-19",
"c", 228, "May-19",
"d", 112, "May-19",
"e", 216, "May-19",
"f", 143, "May-19",
"g", 270, "May-19",
"h", 112, "May-19",
"i", 84, "May-19",
"j", 221, "May-19",
"k", 150, "May-19",
"l", 91, "May-19",
"m", 203, "May-19",
"n", 163, "May-19",
"o", 200, "May-19",
"p", 136, "May-19",
"q", 195, "May-19",
"r", 101, "May-19",
"s", 33, "May-19",
"t", 120, "May-19",
"u", 136, "May-19",
"v", 182, "May-19",
"w", 119, "May-19",
"x", 154, "May-19",
"y", 86, "May-19",
"z", 309, "May-19",
"aa", 138, "May-19",
"bb", 35, "May-19",
"cc", 188, "May-19",
"dd", 93, "May-19",
"ee", 269, "May-19",
"ff", 117, "May-19",
"gg", 163, "May-19",
"hh", 325, "May-19",
"a", 200, "Jun-19",
"b", 207, "Jun-19",
"c", 268, "Jun-19",
"d", 89, "Jun-19",
"e", 222, "Jun-19",
"f", 108, "Jun-19",
"g", 266, "Jun-19",
"h", 79, "Jun-19",
"i", 64, "Jun-19",
"j", 229, "Jun-19",
"k", 120, "Jun-19",
"l", 82, "Jun-19",
"m", 187, "Jun-19",
"n", 143, "Jun-19",
"o", 202, "Jun-19",
"p", 163, "Jun-19",
"q", 166, "Jun-19",
"r", 122, "Jun-19",
"s", 29, "Jun-19",
"t", 130, "Jun-19",
"u", 150, "Jun-19",
"v", 195, "Jun-19",
"w", 98, "Jun-19",
"x", 149, "Jun-19",
"y", 96, "Jun-19",
"z", 251, "Jun-19",
"aa", 114, "Jun-19",
"bb", 39, "Jun-19",
"cc", 176, "Jun-19",
"dd", 99, "Jun-19",
"ee", 255, "Jun-19",
"ff", 154, "Jun-19",
"gg", 125, "Jun-19",
"hh", 339, "Jun-19",
"a", 186, "Jul-19",
"b", 166, "Jul-19",
"c", 265, "Jul-19",
"d", 97, "Jul-19",
"e", 199, "Jul-19",
"f", 98, "Jul-19",
"g", 250, "Jul-19",
"h", 84, "Jul-19",
"i", 58, "Jul-19",
"j", 181, "Jul-19",
"k", 111, "Jul-19",
"l", 83, "Jul-19",
"m", 181, "Jul-19",
"n", 160, "Jul-19",
"o", 165, "Jul-19",
"p", 143, "Jul-19",
"q", 207, "Jul-19",
"r", 84, "Jul-19",
"s", 24, "Jul-19",
"t", 116, "Jul-19",
"u", 153, "Jul-19",
"v", 193, "Jul-19",
"w", 90, "Jul-19",
"x", 131, "Jul-19",
"y", 88, "Jul-19",
"z", 222, "Jul-19",
"aa", 106, "Jul-19",
"bb", 28, "Jul-19",
"cc", 176, "Jul-19",
"dd", 86, "Jul-19",
"ee", 282, "Jul-19",
"ff", 137, "Jul-19",
"gg", 126, "Jul-19",
"hh", 346, "Jul-19",
"a", 192, "Aug-19",
"b", 175, "Aug-19",
"c", 238, "Aug-19",
"d", 73, "Aug-19",
"e", 205, "Aug-19",
"f", 109, "Aug-19",
"g", 235, "Aug-19",
"h", 85, "Aug-19",
"i", 58, "Aug-19",
"j", 149, "Aug-19",
"k", 105, "Aug-19",
"l", 74, "Aug-19",
"m", 173, "Aug-19",
"n", 113, "Aug-19",
"o", 169, "Aug-19",
"p", 127, "Aug-19",
"q", 197, "Aug-19",
"r", 70, "Aug-19",
"s", 26, "Aug-19",
"t", 110, "Aug-19",
"u", 139, "Aug-19",
"v", 198, "Aug-19",
"w", 75, "Aug-19",
"x", 136, "Aug-19",
"y", 105, "Aug-19",
"z", 252, "Aug-19",
"aa", 101, "Aug-19",
"bb", 26, "Aug-19",
"cc", 160, "Aug-19",
"dd", 118, "Aug-19",
"ee", 262, "Aug-19",
"ff", 118, "Aug-19",
"gg", 80, "Aug-19",
"hh", 351, "Aug-19",
"a", 170, "Sep-19",
"b", 143, "Sep-19",
"c", 211, "Sep-19",
"d", 74, "Sep-19",
"e", 170, "Sep-19",
"f", 74, "Sep-19",
"g", 192, "Sep-19",
"h", 83, "Sep-19",
"i", 43, "Sep-19",
"j", 124, "Sep-19",
"k", 92, "Sep-19",
"l", 65, "Sep-19",
"m", 164, "Sep-19",
"n", 110, "Sep-19",
"o", 127, "Sep-19",
"p", 105, "Sep-19",
"q", 171, "Sep-19",
"r", 87, "Sep-19",
"s", 18, "Sep-19",
"t", 92, "Sep-19",
"u", 118, "Sep-19",
"v", 198, "Sep-19",
"w", 81, "Sep-19",
"x", 147, "Sep-19",
"y", 78, "Sep-19",
"z", 248, "Sep-19",
"aa", 79, "Sep-19",
"bb", 34, "Sep-19",
"cc", 158, "Sep-19",
"dd", 84, "Sep-19",
"ee", 244, "Sep-19",
"ff", 104, "Sep-19",
"gg", 98, "Sep-19",
"hh", 323, "Sep-19",
"a", 159, "Jan-20",
"b", 175, "Jan-20",
"c", 229, "Jan-20",
"d", 68, "Jan-20",
"e", 211, "Jan-20",
"f", 93, "Jan-20",
"g", 231, "Jan-20",
"h", 116, "Jan-20",
"i", 60, "Jan-20",
"j", 153, "Jan-20",
"k", 120, "Jan-20",
"l", 117, "Jan-20",
"m", 224, "Jan-20",
"n", 158, "Jan-20",
"o", 172, "Jan-20",
"p", 109, "Jan-20",
"q", 197, "Jan-20",
"r", 113, "Jan-20",
"s", 20, "Jan-20",
"t", 150, "Jan-20",
"u", 130, "Jan-20",
"v", 214, "Jan-20",
"w", 93, "Jan-20",
"x", 158, "Jan-20",
"y", 71, "Jan-20",
"z", 312, "Jan-20",
"aa", 103, "Jan-20",
"bb", 46, "Jan-20",
"cc", 166, "Jan-20",
"dd", 67, "Jan-20",
"ee", 304, "Jan-20",
"ff", 114, "Jan-20",
"gg", 160, "Jan-20",
"hh", 300, "Jan-20",
"a", 170, "Feb-20",
"b", 134, "Feb-20",
"c", 148, "Feb-20",
"d", 79, "Feb-20",
"e", 158, "Feb-20",
"f", 87, "Feb-20",
"g", 183, "Feb-20",
"h", 91, "Feb-20",
"i", 87, "Feb-20",
"j", 106, "Feb-20",
"k", 101, "Feb-20",
"l", 106, "Feb-20",
"m", 229, "Feb-20",
"n", 104, "Feb-20",
"o", 184, "Feb-20",
"p", 91, "Feb-20",
"q", 136, "Feb-20",
"r", 86, "Feb-20",
"s", 12, "Feb-20",
"t", 121, "Feb-20",
"u", 152, "Feb-20",
"v", 214, "Feb-20",
"w", 62, "Feb-20",
"x", 147, "Feb-20",
"y", 74, "Feb-20",
"z", 231, "Feb-20",
"aa", 87, "Feb-20",
"bb", 34, "Feb-20",
"cc", 113, "Feb-20",
"dd", 66, "Feb-20",
"ee", 270, "Feb-20",
"ff", 96, "Feb-20",
"gg", 120, "Feb-20",
"hh", 201, "Feb-20",
"a", 135, "Mar-20",
"b", 173, "Mar-20",
"c", 132, "Mar-20",
"d", 65, "Mar-20",
"e", 126, "Mar-20",
"f", 97, "Mar-20",
"g", 160, "Mar-20",
"h", 96, "Mar-20",
"i", 84, "Mar-20",
"j", 100, "Mar-20",
"k", 85, "Mar-20",
"l", 130, "Mar-20",
"m", 154, "Mar-20",
"n", 79, "Mar-20",
"o", 138, "Mar-20",
"p", 94, "Mar-20",
"q", 118, "Mar-20",
"r", 83, "Mar-20",
"s", 10, "Mar-20",
"t", 70, "Mar-20",
"u", 124, "Mar-20",
"v", 165, "Mar-20",
"w", 31, "Mar-20",
"x", 101, "Mar-20",
"y", 68, "Mar-20",
"z", 190, "Mar-20",
"aa", 70, "Mar-20",
"bb", 31, "Mar-20",
"cc", 86, "Mar-20",
"dd", 47, "Mar-20",
"ee", 187, "Mar-20",
"ff", 73, "Mar-20",
"gg", 125, "Mar-20",
"hh", 197, "Mar-20",
"a", 104, "Apr-20",
"b", 76, "Apr-20",
"c", 98, "Apr-20",
"d", 65, "Apr-20",
"e", 97, "Apr-20",
"f", 69, "Apr-20",
"g", 136, "Apr-20",
"h", 61, "Apr-20",
"i", 75, "Apr-20",
"j", 72, "Apr-20",
"k", 55, "Apr-20",
"l", 69, "Apr-20",
"m", 153, "Apr-20",
"n", 66, "Apr-20",
"o", 123, "Apr-20",
"p", 66, "Apr-20",
"q", 72, "Apr-20",
"r", 41, "Apr-20",
"s", 14, "Apr-20",
"t", 75, "Apr-20",
"u", 75, "Apr-20",
"v", 128, "Apr-20",
"w", 19, "Apr-20",
"x", 77, "Apr-20",
"y", 46, "Apr-20",
"z", 143, "Apr-20",
"aa", 39, "Apr-20",
"bb", 22, "Apr-20",
"cc", 61, "Apr-20",
"dd", 50, "Apr-20",
"ee", 139, "Apr-20",
"ff", 60, "Apr-20",
"gg", 76, "Apr-20",
"hh", 146, "Apr-20",
"a", 166, "May-20",
"b", 131, "May-20",
"c", 168, "May-20",
"d", 77, "May-20",
"e", 145, "May-20",
"f", 68, "May-20",
"g", 215, "May-20",
"h", 80, "May-20",
"i", 79, "May-20",
"j", 101, "May-20",
"k", 98, "May-20",
"l", 92, "May-20",
"m", 175, "May-20",
"n", 124, "May-20",
"o", 133, "May-20",
"p", 110, "May-20",
"q", 138, "May-20",
"r", 70, "May-20",
"s", 18, "May-20",
"t", 76, "May-20",
"u", 93, "May-20",
"v", 208, "May-20",
"w", 26, "May-20",
"x", 147, "May-20",
"y", 60, "May-20",
"z", 247, "May-20",
"aa", 93, "May-20",
"bb", 37, "May-20",
"cc", 119, "May-20",
"dd", 57, "May-20",
"ee", 233, "May-20",
"ff", 48, "May-20",
"gg", 95, "May-20",
"hh", 208, "May-20",
"a", 162, "Jun-20",
"b", 120, "Jun-20",
"c", 159, "Jun-20",
"d", 82, "Jun-20",
"e", 154, "Jun-20",
"f", 93, "Jun-20",
"g", 209, "Jun-20",
"h", 67, "Jun-20",
"i", 65, "Jun-20",
"j", 81, "Jun-20",
"k", 107, "Jun-20",
"l", 82, "Jun-20",
"m", 162, "Jun-20",
"n", 131, "Jun-20",
"o", 139, "Jun-20",
"p", 108, "Jun-20",
"q", 129, "Jun-20",
"r", 62, "Jun-20",
"s", 22, "Jun-20",
"t", 101, "Jun-20",
"u", 97, "Jun-20",
"v", 184, "Jun-20",
"w", 48, "Jun-20",
"x", 129, "Jun-20",
"y", 65, "Jun-20",
"z", 202, "Jun-20",
"aa", 82, "Jun-20",
"bb", 30, "Jun-20",
"cc", 123, "Jun-20",
"dd", 51, "Jun-20",
"ee", 198, "Jun-20",
"ff", 81, "Jun-20",
"gg", 93, "Jun-20",
"hh", 199, "Jun-20",
"a", 110, "Jul-20",
"b", 88, "Jul-20",
"c", 105, "Jul-20",
"d", 65, "Jul-20",
"e", 100, "Jul-20",
"f", 61, "Jul-20",
"g", 177, "Jul-20",
"h", 55, "Jul-20",
"i", 33, "Jul-20",
"j", 91, "Jul-20",
"k", 62, "Jul-20",
"l", 42, "Jul-20",
"m", 134, "Jul-20",
"n", 93, "Jul-20",
"o", 102, "Jul-20",
"p", 97, "Jul-20",
"q", 101, "Jul-20",
"r", 62, "Jul-20",
"s", 7, "Jul-20",
"t", 87, "Jul-20",
"u", 58, "Jul-20",
"v", 143, "Jul-20",
"w", 29, "Jul-20",
"x", 103, "Jul-20",
"y", 69, "Jul-20",
"z", 192, "Jul-20",
"aa", 86, "Jul-20",
"bb", 29, "Jul-20",
"cc", 104, "Jul-20",
"dd", 37, "Jul-20",
"ee", 177, "Jul-20",
"ff", 100, "Jul-20",
"gg", 65, "Jul-20",
"hh", 154, "Jul-20",
"a", 65, "Aug-20",
"b", 40, "Aug-20",
"c", 70, "Aug-20",
"d", 23, "Aug-20",
"e", 63, "Aug-20",
"f", 33, "Aug-20",
"g", 79, "Aug-20",
"h", 36, "Aug-20",
"i", 18, "Aug-20",
"j", 38, "Aug-20",
"k", 21, "Aug-20",
"l", 21, "Aug-20",
"m", 75, "Aug-20",
"n", 40, "Aug-20",
"o", 53, "Aug-20",
"p", 24, "Aug-20",
"q", 52, "Aug-20",
"r", 16, "Aug-20",
"s", 8, "Aug-20",
"t", 53, "Aug-20",
"u", 30, "Aug-20",
"v", 81, "Aug-20",
"w", 15, "Aug-20",
"x", 47, "Aug-20",
"y", 25, "Aug-20",
"z", 103, "Aug-20",
"aa", 37, "Aug-20",
"bb", 13, "Aug-20",
"cc", 37, "Aug-20",
"dd", 18, "Aug-20",
"ee", 75, "Aug-20",
"ff", 45, "Aug-20",
"gg", 49, "Aug-20",
"hh", 63, "Aug-20"
)
d1
interval_value_formatter <- "function(num, opts, seriesName, g, row, col) {
value = g.getValue(row, col);
if(value[0] != value[2]) {
lower = Dygraph.numberValueFormatter(value[0], opts);
upper = Dygraph.numberValueFormatter(value[2], opts);
return '[' + lower + ', ' + upper + ']';
} else {
return Dygraph.numberValueFormatter(num, opts);
}
}"
timeseies1<-ts(d1$AbortionCount,start = c(2019,01),end=c(2020,08),frequency = 12)
timeseies1 %>%
stlf(timeseies1, h = 12) %>%
{cbind(actuals=.$x, forecast_mean=.$mean,
lower_95=.$lower[,"95%"], upper_95=.$upper[,"95%"],
lower_80=.$lower[,"80%"], upper_80=.$upper[,"80%"])} %>%
dygraph(main="random forecasting", ylab = "records") %>%
dyAxis("y", valueFormatter = interval_value_formatter) %>%
dySeries("actuals", color = "black") %>%
dySeries("forecast_mean", color = "blue", label = "forecast") %>%
dySeries(c("lower_80", "forecast_mean", "upper_80"),
label = "80%", color = "blue") %>%
dySeries(c("lower_95", "forecast_mean", "upper_95"),
label = "95%", color = "blue") %>%
dyLegend(labelsSeparateLines=TRUE) %>%
dyRangeSelector() %>%
dyUnzoom() %>%
dyCrosshair(direction = "vertical") %>%
dyOptions(digitsAfterDecimal = 1) %>%
dyCSS(textConnection(".dygraph-legend {background-color: rgba(255, 255, 255, 0.5) !important; }"))
})
}
shinyApp(ui,server)
due to the size limit, I have removed few months of 2019.
any help would be great, Thanks