gpt4 book ai didi

r - 使用reactivePoll 累积数据输出

转载 作者:行者123 更新时间:2023-12-04 11:53:23 26 4
gpt4 key购买 nike

我刚注意到 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 - 使用reactivePoll 累积数据输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19898113/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com