Reputation: 1113
A Bokeh server is running, generating a particular plot. How can another process send a message to the Bokeh server that causes it to discard this plot completely and generate a new plot? The Bokeh server needs to be able to generate one of many different styles of plots based on the message from the other process. It also needs to be able to receive a stream updates to the data in the plot. It may not be relevant but the plots need to be embedded in a page of a Flask application.
EDIT: This question was originally asked with specifics about what I am trying to do, but it received negative feedback for being too broad. I hope I have made it more concise without falling into the XY problem. The goal is to have a Bokeh server displaying plots of live data and have those plots change over time based on running other scripts independent of the Bokeh server.
Upvotes: 1
Views: 675
Reputation: 97301
You can use the asyncio interface of pyzmq to communicate between bokeh server and other processes.
http://pyzmq.readthedocs.io/en/latest/api/zmq.asyncio.html
If you want every session of your application has different process to communicate:
start the process in on_session_created()
of server_lifecycle.py
, and start a task to monitor the incoming pyzmq messages in your bokeh application code:
import zmq
import zmq.asyncio
ctx = zmq.asyncio.Context.instance()
sock = ctx.socket(zmq.XXXX)
sock.bind(.....)
@without_document_lock
async def message_loop():
while True:
message = await sock.recv_pyobj()
process_message(message)
curdoc().add_next_tick_callback(message_loop)
where the sock
is a socket object.
Here is a complete example:
https://gist.github.com/ruoyu0088/ea9a199762993b91f7ca13d0dbdbcdaa
Upvotes: 1