我有一个闪亮的应用程序,可以从SQL查询数据。我在内部服务器上运行它,并希望数据每小时左右自动刷新一次。
到目前为止,这仅在我将 shinApp 文件新放入服务器上并首次运行它时才有效。之后,每当我重新加载链接时,数据都不会改变。
我尝试使用如下所示的无效,但它不会刷新数据。
shinyServer(function(input, output, session) {
sourceData <- reactive({
invalidateLater(3000000,session)
return(sourceData())
})
.
.
.
})
其中定义了 sourceData()
sourceData<-function(){
data1 <<- get_data1( 'query here' )
data2 <<- get_data2( 'query here' )
}
有人遇到过这个问题吗?
我看到 reactivepoll() 是另一种选择。valueFunc 将是我的源数据,但不确定如何将 checkFunc 集成到我的上下文中。
如果您不想使用 sourceData() 返回任何内容,因为这是它看起来的方式,您可以执行以下操作之一:
1
# sourceData() shouldn't return anything but it will still write into data1 and data2
sourceData <- reactive({
invalidateLater(3000000,session)
data1 <<- get_data1( 'query here' )
data2 <<- get_data2( 'query here' )
})
阿拉伯数字
# This is the preferred option as it seems to me you don't want to use sourceData() but rather the data1 and data2
sourceData <- observe({
invalidateLater(3000000,session)
data1 <<- get_data1( 'query here' )
data2 <<- get_data2( 'query here' )
})
还要研究 reactivePoll,并且有一些示例说明如何在 reactivePoll 和 reactiveFileReader 中构建它。