Search code examples
python-3.xbokehgraphinggraph-visualization

Graphing Simulation with Bokeh


I want to use Bokeh to graph real-time data from a simulation script. Basically, the simulation will be the source of the 'real-time' streaming data and I want the Bokeh graphs to update every time my simulation script tells it to. I also want to start the Bokeh server programatically and didn't want to block the main thread so that's why I started with the standalone embed example:

https://github.com/bokeh/bokeh/blob/0.12.4/examples/howto/server_embed/standalone_embed.py

However, I realized that using this example as a starting point might be flawed as once I start the IOloop no other code below it can run, which is an issue because all my simulation code needs to be running while the Bokeh server is also running.

Can someone push me in the right direction of how to accomplish this? Basically, I need to send updates to Bokeh to update its graphs whenever the simulation script tells it to and need to have the bokeh graphs show / be interactive at the same time as my simulation code script is running. I would also like to keep it as separated as possible (i.e run the simulation on its own without any bokeh graphing being started up or visa versa - don't want to muddy up my original simulation code in order to make this work)


Solution

  • Just posting if anyone was curious. Made a toy example in which I had a script run and produce some 'data'. Ran it using bokeh serve --show run.py in order to also get the bokeh server running.

    My toy example:

    https://github.com/hhprogram/Learning_Examples/tree/master/BokehTest

    These examples were helpful:

    https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram

    https://docs.bokeh.org/en/latest/docs/user_guide/server.html#updating-from-threads

    Ideally, I would be able to just open my bokeh server app separately and then run my python script whenever I wanted and once that script was up and running and producing data then my bokeh graphs would update but haven't gotten to implementing that as of yet. Hope this is helpful to some and open to criticism of my code so don't be shy.