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

我想将数据累积到矢量,列表或data.frame中(无关紧要),然后绘制数据,UI展示了一个图表,其中随着新数据的到来累积了数据。问题是我看不到如何在不替换旧数据的情况下将新数据添加到旧数据。在此示例(https://gist.github.com/sckott/7388855)中,我仅获得data.frame中的第一行,以及最新的行,而不是所有数据的累积。对于此示例,如何使data.frame增长,在底部添加新数据?

最佳答案

这可以使用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
      })
    })
)

关于r - 使用reactPoll累积数据以进行输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19898113/

10-12 13:57
查看更多