Initiate and append Websocket updates to clientside variable

The example sends a full new dataset (array with 10 random numbers) in each ws msg, and then plots this new data series. Another (probably more common) real-world scenario would be a websocket feed with a new additional datapoint in each ws msg, to form a live expanding time-series.

Using the clientside callback makes perfect sense to me in terms of performance and data transfer so I would like to keep that.
How would I initiate and then append a (global) variable, clientside, with the new data as it comes in, so that I can plot a live expanding timeseries graph?

Thank you for any help!

I recently wrote the SSE component to enable a ChatGPT-like UI with text streaming,

I haven’t gotten around to writing docs for it yet, but depending on your use case it might serve as (part of) a solution. Or simply as inspiration :blush:

2 Likes

Thanks for the reply Emil. I think my understanding is not solid enough yet to grasp how your code helps me reach my goal.

I’m starting to think it makes more sense for live websocket graphing to use plotly.js such that everything runs client side? Rather than bending something which is designed to be server side to act more client side…

The benefit of the SSE component is that it supports buffering (concatenation) of data out of the box. You could in principle do the same with a websocket component and clientside callback(s), but I suspekt it will be less robust (e.g. you might loose some data, if the streaming is fast).