I just noticed reactivePoll()
recently - but need a bit of help figuring it out for my use case.
I want to accumulate data into a vector, list, or data.frame (doesn't matter), then plot the data, with the UI showing a graph with data accumulating as new data comes in. The problem is I don't see how to add new data to old data without replacing the old data. In this example (https://gist.github.com/sckott/7388855) I only get the initial row in the data.frame, and the newest one, not an accumulation of all data. For this example, how can I get the data.frame
to grow, adding new data at the bottom?
This can be done using the reactiveValues
function:
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
})
})
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With