why aggregate is not working for forecasting

I wanna do forecasting only for the next two years (month-wise) then why is it showing actual value for way too much more years ahead even after applying the aggregate function, I don't know what I am missing here.
could anyone please guide me through.

library(shiny)
library(dygraphs)
library(forecast)
library(tseries)
ui<-fluidPage(
  fluidRow(
    dygraphOutput("dychart")
  )
)
server<-function(input,output){
  output$dychart <- renderDygraph({
    qry2<-read.csv("c:/users/nic user/desktop/ab.csv")
    data1<-aggregate(qry2$AbortionCount,by=list(qry2$Month,qry2$Unitname),FUN=sum)
    
    
    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);
  }
}"
    timetravel<-ts(data1$x,start = c(2019,1),frequency = 12)
    timetravel %>%
      stlf(lambda = 0, h = 24) %>%
      {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 Records", ylab = "DATA") %>%
      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() %>%
      dyOptions(digitsAfterDecimal = 1) %>%
      dyCSS(textConnection(".dygraph-legend {background-color: rgba(255, 255, 255, 0.5) !important; }"))
    
  })
  
}
shinyApp(ui,server)

why is it not working even after applying the aggregate function?

sorry, I forget to mention that the data looks like this...

Unitname	AbortionCount	Month
a	176	Jan-19
b	245	Jan-19
c	279	Jan-19
d	106	Jan-19
e	213	Jan-19
f	150	Jan-19
g	273	Jan-19
h	96	Jan-19
i	69	Jan-19
j	249	Jan-19
k	119	Jan-19
l	107	Jan-19
m	265	Jan-19
n	179	Jan-19
o	197	Jan-19
p	141	Jan-19
q	192	Jan-19
r	90	Jan-19
s	22	Jan-19
t	116	Jan-19
u	159	Jan-19
v	227	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	195	Oct-19
b	142	Oct-19
c	211	Oct-19
d	71	Oct-19
e	174	Oct-19
f	78	Oct-19
g	216	Oct-19
h	66	Oct-19
i	44	Oct-19
j	139	Oct-19
k	100	Oct-19
l	63	Oct-19
m	175	Oct-19
n	122	Oct-19
o	109	Oct-19
p	89	Oct-19
q	190	Oct-19
r	81	Oct-19
s	11	Oct-19
t	100	Oct-19
u	129	Oct-19
v	211	Oct-19
w	58	Oct-19
x	145	Oct-19
y	83	Oct-19
z	231	Oct-19
aa	70	Oct-19
bb	26	Oct-19
cc	135	Oct-19
dd	73	Oct-19
ee	266	Oct-19
ff	143	Oct-19
gg	141	Oct-19
hh	284	Oct-19
a	158	Nov-19
b	113	Nov-19
c	182	Nov-19
d	65	Nov-19
e	157	Nov-19
f	65	Nov-19
g	213	Nov-19
h	82	Nov-19
i	46	Nov-19
j	153	Nov-19
k	78	Nov-19
l	65	Nov-19
m	208	Nov-19
n	149	Nov-19
o	105	Nov-19
p	63	Nov-19
q	162	Nov-19
r	74	Nov-19
s	12	Nov-19
t	98	Nov-19
u	119	Nov-19
v	187	Nov-19
w	46	Nov-19
x	144	Nov-19
y	65	Nov-19
z	227	Nov-19
aa	60	Nov-19
bb	15	Nov-19
cc	129	Nov-19
dd	64	Nov-19
ee	192	Nov-19
ff	101	Nov-19
gg	138	Nov-19
hh	219	Nov-19
a	155	Dec-19
b	107	Dec-19
c	162	Dec-19
d	66	Dec-19
e	157	Dec-19
f	80	Dec-19
g	154	Dec-19
h	56	Dec-19
i	48	Dec-19
j	129	Dec-19
k	81	Dec-19
l	64	Dec-19
m	228	Dec-19
n	149	Dec-19
o	100	Dec-19
p	84	Dec-19
q	166	Dec-19
r	68	Dec-19
s	7	Dec-19
t	69	Dec-19
u	85	Dec-19
v	169	Dec-19
w	50	Dec-19
x	143	Dec-19
y	64	Dec-19
z	199	Dec-19
aa	56	Dec-19
bb	15	Dec-19
cc	105	Dec-19
dd	50	Dec-19
ee	207	Dec-19
ff	117	Dec-19
gg	116	Dec-19
hh	183	Dec-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
a	110	Sep-20
b	88	Sep-20
c	105	Sep-20
d	65	Sep-20
e	100	Sep-20
f	61	Sep-20
g	177	Sep-20
h	55	Sep-20
i	33	Sep-20
j	91	Sep-20
k	62	Sep-20
l	42	Sep-20
m	134	Sep-20
n	93	Sep-20
o	102	Sep-20
p	97	Sep-20
q	101	Sep-20
r	62	Sep-20
s	7	Sep-20
t	87	Sep-20
u	58	Sep-20
v	143	Sep-20
w	29	Sep-20
x	103	Sep-20
y	69	Sep-20
z	192	Sep-20
aa	86	Sep-20
bb	29	Sep-20
cc	104	Sep-20
dd	37	Sep-20
ee	177	Sep-20
ff	100	Sep-20
gg	65	Sep-20
hh	154	Sep-20
a	110	Oct-20
b	88	Oct-20
c	105	Oct-20
d	65	Oct-20
e	100	Oct-20
f	61	Oct-20
g	177	Oct-20
h	55	Oct-20
i	33	Oct-20
j	91	Oct-20
k	62	Oct-20
l	42	Oct-20
m	134	Oct-20
n	93	Oct-20
o	102	Oct-20
p	97	Oct-20
q	101	Oct-20
r	62	Oct-20
s	7	Oct-20
t	87	Oct-20
u	58	Oct-20
v	143	Oct-20
w	29	Oct-20
x	103	Oct-20
y	69	Oct-20
z	192	Oct-20
aa	86	Oct-20
bb	29	Oct-20
cc	104	Oct-20
dd	37	Oct-20
ee	177	Oct-20
ff	100	Oct-20
gg	65	Oct-20
hh	154	Oct-20
a	110	Nov-20
b	88	Nov-20
c	105	Nov-20
d	65	Nov-20
e	100	Nov-20
f	61	Nov-20
g	177	Nov-20
h	55	Nov-20
i	33	Nov-20
j	91	Nov-20
k	62	Nov-20
l	42	Nov-20
m	134	Nov-20
n	93	Nov-20
o	102	Nov-20
p	97	Nov-20
q	101	Nov-20
r	62	Nov-20
s	7	Nov-20
t	87	Nov-20
u	58	Nov-20
v	143	Nov-20
w	29	Nov-20
x	103	Nov-20
y	69	Nov-20
z	192	Nov-20
aa	86	Nov-20
bb	29	Nov-20
cc	104	Nov-20
dd	37	Nov-20
ee	177	Nov-20
ff	100	Nov-20
gg	65	Nov-20
hh	154	Nov-20
a	110	Dec-20
b	88	Dec-20
c	105	Dec-20
d	65	Dec-20
e	100	Dec-20
f	61	Dec-20
g	177	Dec-20
h	55	Dec-20
i	33	Dec-20
j	91	Dec-20
k	62	Dec-20
l	42	Dec-20
m	134	Dec-20
n	93	Dec-20
o	102	Dec-20
p	97	Dec-20
q	101	Dec-20
r	62	Dec-20
s	7	Dec-20
t	87	Dec-20
u	58	Dec-20
v	143	Dec-20
w	29	Dec-20
x	103	Dec-20
y	69	Dec-20
z	192	Dec-20
aa	86	Dec-20
bb	29	Dec-20
cc	104	Dec-20
dd	37	Dec-20
ee	177	Dec-20
ff	100	Dec-20
gg	65	Dec-20
hh	154	Dec-20

Why aggregate by unit name (which makes every entry unique in combination with month so no aggregation is happening?)

I have tried by removing that unit name and grouping them on the basis of the month only, it is still not working.

you wil lneed to be more specific... about whats 'not working'.
clearly the following code produces different results

(x1 <- aggregate(qry2$AbortionCount,by=list(qry2$Month,qry2$Unitname),FUN=sum))
(x2 <- aggregate(qry2$AbortionCount,by=list(qry2$Month),FUN=sum))
nrow(x1)
# 578
nrow(x2)
# 17

going from 578 rows 'aggregated' (not really)
to 17 rows, aggregated.

I used the data from your previous forum thread where you included it as a tibble as it was convenient.

with a single parameter in the list .the result would be following...

library(shiny)
library(dygraphs)
library(forecast)
library(tseries)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(readr)

    qry2<-read.csv("c:/users/nic user/desktop/ab.csv")
    data1<-aggregate(qry2$AbortionCount,by=list(qry2$Month),FUN=sum)
  
  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);
  }
}"
    timetravel<-ts(data1$x,start = 2019,frequency = 12)
    timetravel %>%
      stlf(lambda = 0, 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 Records", ylab = "DATA") %>%
      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() %>%
      dyOptions(digitsAfterDecimal = 1) %>%
      dyCSS(textConnection(".dygraph-legend {background-color: rgba(255, 255, 255, 0.5) !important; }"))

output:
Error in stl(ts(deseas, frequency = msts[i]), s.window = s.window[i], : series is not periodic or has less than two periods
Created on 2020-09-15 by the reprex package (v0.2.1)
with two-parameter in the list, the result would be

library(shiny)
library(dygraphs)
library(forecast)
library(tseries)
library(dplyr)
library(readr)

qry2<-read.csv("c:/users/nic user/desktop/ab.csv")
data1<-aggregate(qry2$AbortionCount,by=list(qry2$Month,qry2$Unitname),FUN=sum)

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);
  }
}"
timetravel<-ts(data1$x,start = 2019,frequency = 12)
timetravel %>%
  stlf(lambda = 0, 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 Records", ylab = "DATA") %>%
  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() %>%
  dyOptions(digitsAfterDecimal = 1) %>%
  dyCSS(textConnection(".dygraph-legend {background-color: rgba(255, 255, 255, 0.5) !important; }"))

output:----

Note:- If I try to add a single parameter then it throws the time period error and it displays the wrong chart when I add two-parameter , I can not add the dummy data in order to complete the forecasting as this is all the real-time data that I have to work on.

could you please suggest to me what I should do to get rid of this kinda stuck situation.

I think we are repeating previous conversations...
the first is failing because you have something like 17months data, so how many periods of 12 , is that ... less than 2 hence stfl error.
In the second, its not arggregating so the 500+ repeated months are naively being turned into a long stream of numbers each the ts believes is a month in itselfs, thats why you can compute (more than 2 periods) but you get large future values) the months being used are disaggregated.

Sorry for the repetition of the previous thread,I just included it since it was related to the current context.
could you please tell me how I could correct it if aggregate function is not working the way I want .

any suggestion would be great help

The problem is fundamentally with your data isnt it ? its too short to perform the desired analysis.
if you are doing analysis at monthly data, and you want to use the stfl for the periodicity etc, then you need more than 24 months...
Can you go back to your data source and get more (earlier) data ?

Thanks, @nirgrahamuk after adding the more dummy data it is working, since we have started to record the data just about one and half years back, we don't have sufficient data to predict the values ahead, we will start this procedure when we will have enough data to back our forecasting.and for real-time application, we can not add the dummy data.

Thanks for bearing with me this long, really appreciate your concern.

By the way, the output looks fine after your suggestion.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.