I am trying to make a Bokeh plot that updates whenever it receives data. I am using add_next_tick_callback(listener)
to get data posted with queries using curl "http://localhost:5006/mviz/?vpom=0.9&rpom=0.9"
. Data is read correctly when sent using curl but,
- The plot in the browser does not update upon call to
source.stream
. - Upon sending data multiple times, I expected it to append the new data to
source.data
each time increasing the number of rows. But even on hitting thecurl
command above multiple times, it only prints same number of rows each time (with only four rows, one new row appended to the three rows at initialization).
Following is the script I have in file mviz.py
that I run by calling bokeh serve mviz.py
using Bokeh version 1.0.4:
from bokeh.layouts import column
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, curdoc
from bokeh.server.server import Server
source = ColumnDataSource({"vpom": [0.1, 0.2, 0.3], "rpom": [0.2, 0.3, 0.4]})
fig = figure(title='Streaming Circle Plot!', sizing_mode='scale_width',
x_range=[0, 1], y_range=[0, 1])
fig.circle(source=source, x='vpom', y='rpom', size=10)
curdoc().add_root(column(fig))
curdoc().title = "Now with live updating!"
def listener():
req = curdoc().session_context
if req is not None:
args = req.request.arguments
print "recv", args
if args:
source.stream({k:map(float,v) for k,v in args.items()}, 100)
print source.data
curdoc().add_next_tick_callback(listener)
Can someone please point issues with the above script and comment if this is the correct way to use Boekh for this usecase.