Hello,
I am a new user of Bokeh, and am attempting to build out a very simple application that uses bokeh serve to plot data streamed from the client (currently I’m using canned data but eventually you could imagine this connected to an embedded hardware target like a thermometer that is providing time-series data to be plotted). However, it seems like the loop_until_closed function recommended by the various server examples is at odds with interactive usage, since (as far as I’ve been able to tell) there is no way to get it to halt and return short of restarting the client python interpreter. So I have a couple of questions:
-
Is there any way to get session.loop_until_closed() to return? I would have thought that closing the browser window rendering the plot might have done it but that doesn’t seem to be the case…
-
If there is not, that’s fine but is there any other way to launch the server session with periodic callbacks running, that would (ideally) kick the event loop into a background process so that the python interpreter can be used to run other commands even as the plot is streamed to the browser, OR (less ideal but still much better than what I have) is there a way I can do this type of plot such that when I close the plot in the browser, this is detected and code after loop_until_closed() can be run?
I apologize if this is not the right venue for this type of question but I’m hoping that someone can help - I really like the idea of bokeh but I’m having trouble getting from canned examples into writing my own code at this point. A couple other details are below. Thanks in advance!
Brian
Implementation details:
Bokeh version: 0.11
Python: Anaconda 2.4.1 (Python 2.7.x), 64-bit
Operating System: Windows 7 x64
Default browser: Chrome
The code I’m attempting to run
import time
from random import shuffle
import numpy as np
from bokeh.client import push_session
from bokeh.plotting import figure, show, curdoc
from bokeh.models import HoverTool
p = figure(plot_width=600, plot_height=600, tools=‘pan,box_zoom,box_select,crosshair,resize,reset,hover’)
p = figure(x_range=(-1, 20), y_range=(-2,2), plot_width=400, plot_height=400)
r1 = p.line([0], [0], name=‘ex_line’)
session = push_session(curdoc())
ds = r1.data_source
i = 1
def update():
global i
ds.data['x'].append(i)
ds.data['y'].append(np.random.random())
ds.trigger('data',ds.data,ds.data)
i = i + 1
curdoc().add_periodic_callback(update,100)
session.show()
session.loop_until_closed()
``