【问题标题】:shiny trigger refresh data - invalidate not working闪亮的触发器刷新数据 - 无效不起作用
【发布时间】:2015-01-26 09:41:56
【问题描述】:

我有一个闪亮的应用程序,可以从 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 将是我的 sourceData,但不确定如何在我的上下文中集成 checkFunc。

【问题讨论】:

    标签: r shiny reactive-programming invalidation


    【解决方案1】:

    如果您不希望使用 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' )
        })
    

    2

    # 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' )
    })
    

    还请查看reactivePollreactivePoll and reactiveFileReader 中提供了如何构建它的示例

    【讨论】:

    • 我编辑了这个问题。 sourceData() 确实包含查询。至于响应式轮询,我如何将 checkFunc 集成到我的上下文中?
    • 谢谢,至于 1) 这就是我所拥有的(在删除 return() 之后)。对于 2) 我尝试了 observe() 选项,但在这种情况下它不会停止刷新数据。是的,我看到了 reactivePoll 示例,但是我将如何将 checkFunc 准确地集成到我的上下文中?
    • 在此处查看按钮上的示例github.com/decastillo/forc/blob/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    • 2013-12-04
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2018-04-15
    • 2017-09-10
    相关资源
    最近更新 更多