【发布时间】:2020-12-21 06:39:26
【问题描述】:
当我试图绘制从输入变量中获得的数据时,该输入变量会根据区域的选择而变化,我收到一个错误,说我没有使用反应式表达式,但我已经在server.R 文件。
library(shiny)
library(forecast)
shinyServer(function(input, output) {
reactive(if(input$Region == 'India')
df<-read.csv('COVID.csv',row.names=1)
else if(input$Region == 'Telangana')
df<-read.csv('ts_covid.csv',row.names=1)
else
df<-read.csv('ghmc_covid.csv',row.names=1),
quoted=TRUE)
mdl<-auto.arima(df$DailyCases)
future<-forecast(mdl,h=input$Days,level=95)
output$Plot1<-renderPlot({
plot(future)
})
})
.getReactiveEnvironment()$currentContext() 中的错误: 如果没有活动的反应上下文,则不允许操作。 (你试图做一些只能在反应式表达式或观察者内部完成的事情。)
这里是 ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("Forecast of COVID Cases"),
sidebarLayout(
sidebarPanel(
h3('Select the Region where you want the forecast'),
selectInput("Region","Region to be selected",choices=
list('India','Telangana','GHMC')),
h3('Select for how many days you want the forecast for'),
numericInput('Days','Number of Days',value=7,min=1,max=30,step=1)
),
mainPanel(
plotOutput("Plot1")
)
)
))
【问题讨论】:
标签: r shiny reactive-programming shinyapps