【问题标题】:Use reactivePoll to accumulate data for output使用 reactivePoll 累积数据以供输出
【发布时间】:2013-11-11 02:54:50
【问题描述】:

我最近才注意到reactivePoll() - 但需要一些帮助来解决我的用例。

我想将数据累积到向量、列表或 data.frame 中(没关系),然后绘制数据,UI 显示一个图表,其中数据随着新数据的进入而累积。问题是我没有'看不到如何在不替换旧数据的情况下将新数据添加到旧数据中。在这个例子中 (https://gist.github.com/sckott/7388855) 我只得到了 data.frame 中的初始行和最新的行,而不是所有数据的累积。对于这个例子,如何让data.frame 增长,在底部添加新数据?

【问题讨论】:

  • 你遇到过这个问题吗?
  • 我想我做到了,我会挖掘笔记并尽快回复......

标签: r shiny


【解决方案1】:

这可以使用reactiveValues 函数来完成:

runApp(
  list(
    ui = 
      mainPanel(
        tableOutput(outputId="dataTable")
      ),
    server = function(input, output, session) {
      myReact <- reactiveValues(df =data.frame(time=Sys.time()))
      readTimestamp <- function() Sys.time()
      readValue <- function(){
        data.frame(time=readTimestamp())
      }
      data <- reactivePoll(1000, session, readTimestamp, readValue)
      observe({
        myReact$df <- rbind(isolate(myReact$df), data())
      })
      output$dataTable <- renderTable({
        myReact$df
      })
    })
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    相关资源
    最近更新 更多