WebsocketDataSource or client-side (stand-alone) data update?

I am using Bokeh as part of the data visualization end of a simulation framework that requires connections to multiple external resources (database/middleware stuff). Because the middleware doesn’t allow duplicate client names, and because I need a two-way connection between server and clients, I wrote a “plot manager” that handles the middleware callbacks and the bokeh plot generation in a single instance, then sends the JSON item via websockets to any connected clients, for embedding in the site. The ws implementation also handles my middleware interactions.

I’m looking to lighten the load on the client side by using a streaming approach rather than occasionally replacing the embedded image. I have the option of using another port with SSE and a ServerSentDataSource, but I would prefer to use the already existing web socket connection. Is there any way to use/add something like a “WebsocketDataSource” (which I expect would be much like the SSE DataSource wrapper), or to use the client-side javascript to update the data, instead of removing the old figure and re-embedding with the updated contents?

You can already stream new data and patch the old data using Bokeh’s ColumnDataSource. You will still have to replace the whole image in the data source because it’s just a single datum.

I know this is true for cases where I’m using the Bokeh server as part of the system. However, I’m trying to integrate with a framework that uses Apache + websockets, and I need to be able to feed updates from my other middleware connection. So, I’m working from the assumption that I’d generate a skeleton for the figure, and pass that along to the client via websockets for the initial embed, as I’m doing now. How can I get ColumnDataSource to connect to my ws setup (without depending on the bokeh server)?

So your setup is basically BokehJS + whatever backend, without using Bokeh-specific WS connection.
You can still stream and patch data, only the relevant method will be called in JS and not in Python. Because of that, you will have to deliver the data yourself, as you say, but it should work just fine.

I see. Given the BokehJS API is still experimental, I’d rather keep the bulk of my code on the Python side of the equation for now. It seems I might be better off configuring a second port on my server, to use for SSE as per the original plan. It’s too bad there’s no ws equivalent at the moment…

Thanks for the help!

FWIW I would not expect source.stream or source.patch or setting source.data to ever change. Those are not the parts of BokehJS that might change.