4

我正在尝试从 R 的数据库动态构建数据集。下面是我用于相同的代码,但在运行它时出现错误。应用程序正在闪亮运行。

query <- "select * from rdataset" # [col-2]dataset name [col-3]Query
qresult<- dbGetQuery(con,query)
dataset <- reactiveValues()
for (i in 1:nrow(qresult))  {  
   qresult1 <- dbGetQuery(con,qresult[i,3])  # fetching the data from db   
   dataset$qresult[i,2] <- qresult1 #assigning it to dataset so that it can be used later
}
#dataset$MOH<- qresult1 # this line works

运行时出现以下错误

Error in .getReactiveEnvironment()$currentContext() : 
  Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive function.)
4

1 回答 1

2

我在 Shiny 中有同样的错误

错误样本

beta_reactive <- reactive({input$beta})
beta_coeff <- beta_reactive()

output$distPlot <- renderPlot({...})

解决方案

beta_reactive <- reactive({input$beta})
output$distPlot <- renderPlot({
    ...
    beta_coeff <- beta_reactive()    
    ...
})     

反应性内容似乎是一个函数 renderPlot()。可能是反应性的,因为它与输出交互..

于 2020-05-19T14:17:09.963 回答