0
我使用閃亮的應用程序來製作一些預測圖表。但是,我有一個問題,該應用程序只顯示一些圖。我目前使用下面的代碼爲應用程序的服務器部分。閃亮的應用程序,只顯示一些圖表
server <- function(input, output) {
output$graph <- renderPlot({
row.number <- which(grepl(input$n1, Data$Kontotal))
name <- Data [row.number, -(1:3)]
name <- t(name)
name <- ts(name, frequency=12, start=c(2007,1))
n.row <- nrow(name)
en<-max(time(name))
ds<-as.data.frame(window(name,end=en))
names(ds)<-'obs'
ds$date<-as.Date(time(window(name,end=en)))
p1a <- ggplot(data=ds,aes(x=date,y=obs))
p1a <- p1a+geom_line(col='red')
p1a <- p1a+scale_x_date(name='',breaks='1 year',minor_breaks='1 month',labels=date_format("%b-%y"),expand=c(0,0))
p1a <- p1a+scale_y_continuous(name='mio.kr')
p1a <- p1a + theme_bw() +
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) })
output$graph2 <- renderPlot({
if (input$n3 == "HW") {
row.number <- which(grepl(input$n1, Data$Kontotal))
name <- Data [row.number, -(1:3)]
name <- t(name)
name <- ts(name, frequency=12, start=c(2007,1))
n.row <- nrow(name)
fit <- auto.arima (name)
fcast <- forecast(fit, input$n2)
### Plotting
data.pred <- forc.ggplot (name, fcast)
p1a <- ggplot(data=data.pred,aes(x=date,y=obs))
p1a <- p1a+geom_line(col='red')
p1a <- p1a+geom_line(aes(y=fitted),col='blue')
p1a <- p1a+geom_line(aes(y=forecast))+geom_ribbon(aes(ymin=lo95,ymax=hi95),alpha=.25)
p1a <- p1a+scale_x_date(name='',breaks='1 year',minor_breaks='1 month',labels=date_format("%b-%y"),expand=c(0,0))
p1a <- p1a+scale_y_continuous(name='mio.kr')
p1a <- p1a + theme_bw() +
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"))
p1a
}
if (input$n3 == "arima") {
row.number <- which(grepl(input$n1, Data$Kontotal))
name <- Data [row.number, -(1:3)]
name <- t(name)
name <- ts(name, frequency=12, start=c(2007,1))
n.row <- nrow(name)
fit <- auto.arima (name)
fcast <- forecast(fit, input$n2)
### Plotting
data.pred <- forc.ggplot (name, fcast)
p1a <- ggplot(data=data.pred,aes(x=date,y=obs))
p1a <- p1a+geom_line(col='red')
p1a <- p1a+geom_line(aes(y=fitted),col='blue')
p1a <- p1a+geom_line(aes(y=forecast))+geom_ribbon(aes(ymin=lo95,ymax=hi95),alpha=.25)
p1a <- p1a+scale_x_date(name='',breaks='1 year',minor_breaks='1 month',labels=date_format("%b-%y"),expand=c(0,0))
p1a <- p1a+scale_y_continuous(name='mio.kr')
p1a <- p1a + theme_bw() +
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"))
p1a
}
})
}
的問題是,只有ARIMA圖表表示。 注意,但是,在這裏發佈的代碼中,我在代碼的HW部分中更改了模型,因此它與ARIMA部分(包括模型)是相同的,只是爲了檢查是因爲某些部分出錯ets函數(我用來估計HW模型)。
它簡單地留下了一個空白區域,其中圖形應該在HW的情況下,但繪製了ARIMA模型的右圖。
有人試過類似的東西嗎?
請將'ui.r' –