使用reactivePoll累积输出数据

sck*_*ott 7 r shiny

reactivePoll()最近才注意到- 但需要一点帮助才能找出我的用例.

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

jdh*_*son 7

这可以使用以下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
      })
    })
)
Run Code Online (Sandbox Code Playgroud)