0

I have a device streaming data to the PC and I would like to use R to produce real-time streaming plots. I realize that Javascript is probably the best tool for this, but I don't have the skill set for reading data and plotting in Javascript.

I am aware of gganimate, gifski, etc. for animated gifs, but I don't think those will be able to stream data.

I have tried Shiny with invalidateLater and it works, but struggles to update faster than about 5 frames per second.

I have tried to run an R process to generate images on a timer and a simple html page that loads the image every 100 ms, but this produces frequent broken links when the html page is trying to load an image that R is actively writing.

Are there any other options in R that don't involve learning Javascript or Javascript packages? Any other general advice?

Arthur
  • 1,248
  • 8
  • 14
  • Interesting question ... I don't know of any R package that facilitates streaming _any_ data, whether animations or not. Granted, it's not cosmic to think that a function can repeatedly export data that is sent across the wire, but most of shiny and plumber apps (in my experience) tend to rely on intermittent availability of the R interpreter periodically using `promises`, perhaps going multi-proc with `future` or `callr`. What _consumer_ do you have in mind? – r2evans Sep 20 '22 at 13:25
  • That is, if all you want is an image that self-updates at a low frequency, then can brute-force it, but I'm not familiar with available protocols to know which format/protocol is best for your needs. Perhaps you can expand on that? Vector/raster? – r2evans Sep 20 '22 at 13:25
  • The customer is the audience of a demo of the data-streaming device. I'm totally agnostic on image format. There might be some opportunity for `future` in the data processing and plotting, but I think that Shiny itself might be a bottleneck on the animation. Suspect there's a lot of data going back and forth between R and Javascript that sets a limit on frame rate. – Arthur Sep 20 '22 at 13:48
  • 1
    Not a lot of help, but perhaps a side-channel HTTP handler with in-R processing? https://stackoverflow.com/a/25299306/3358272. It still requires javascript handling, but might allow you to pick up the pace ... though I'm really not convinced that in-shiny is the best way, since method still dominates the current R process, requiring some form of concurrency. – r2evans Sep 20 '22 at 14:06
  • https://coolbutuseless.github.io/package/eventloop/articles/stream-plotting.html – Jon Spring Sep 20 '22 at 16:42

0 Answers0