Store data received using websocket

Hi all,

how can I store data received from websocket API? We all know how to print it to console:

ws$onMessage(function(event) {
cat("Client got msg:", event$data, "\n")
})

But what I would like to do is something like:
ws$onMessage(function(event) {
result <- as.data.frame(fromJSON(event$data))
})

I know my connection works okay and when I write the result as csv inside the onMessage function, it works but the result object does not show in the environment.

What can be done to actually get the data frame from the call in the global environment?

is this in shiny ?
you would not typically use traditional global objects in shiny.
you would use some variety of reactive, maybe a reactivelist you could grow.
if you need to end the app and have the final result somewere, then you'd probably make a button (that you could press before quiting) to write your reactive object to disk (or potentially to the global environment maybe with an assign or <<- syntax

It is not shiny, but the <<- helped! Thank you a lot, I completely forgot about this syntax :slight_smile: How simple...

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.