I am running a bokeh server app which uses a streaming dataset. Lets use a simple example
from bokeh.plotting import figure, curdoc
from bokeh.driving import linear
import random
p = figure(plot_width=400, plot_height=400)
r = p.line(, , color=“firebrick”, line_width=2)
ds = r.data_source
@linear()
def update(step):
ds.data[‘x’].append(step)
ds.data[‘y’].append(random.randint(0,100))
ds.trigger(‘data’, ds.data, ds.data)
curdoc().add_root(p)
Add a periodic callback to be run every 500 milliseconds
curdoc().add_periodic_callback(update, 500)
``
I would like to stop the streaming and plotting after a certain point (when x =10). How do I do that? I tried using remove_periodic_callback(update) but it does not work from within the callback function.
Hi there, I checked your code using Bokeh 1.0.4 and it shows that it actually works: plotting stops after 10 steps
from bokeh.plotting import figure, curdoc
from bokeh.driving import linear
import random
p = figure(plot_width = 400, plot_height = 400)
r = p.line(, , color = “firebrick”, line_width = 2)
ds = r.data_source
@linear()
def update(step):
ds.data[‘x’].append(step)
ds.data[‘y’].append(random.randint(0, 100))
ds.trigger(‘data’, ds.data, ds.data)
if step == 10:
curdoc().remove_periodic_callback(pc_id)
curdoc().add_root(p)
pc_id = curdoc().add_periodic_callback(update, 1000)
``
···
On Wednesday, March 6, 2019 at 11:53:38 PM UTC+1, Kaushik Mallick wrote:
I am running a bokeh server app which uses a streaming dataset. Lets use a simple example
from bokeh.plotting import figure, curdoc
from bokeh.driving import linear
import random
p = figure(plot_width=400, plot_height=400)
r = p.line(, , color=“firebrick”, line_width=2)
ds = r.data_source
@linear()
def update(step):
ds.data[‘x’].append(step)
ds.data[‘y’].append(random.randint(0,100))
ds.trigger(‘data’, ds.data, ds.data)
curdoc().add_root(p)
Add a periodic callback to be run every 500 milliseconds
curdoc().add_periodic_callback(update, 500)
``
I would like to stop the streaming and plotting after a certain point (when x =10). How do I do that? I tried using remove_periodic_callback(update) but it does not work from within the callback function.
Thanks for checking and confirming. I am glad to hear it works now.
···
On Thursday, March 7, 2019 at 8:56:25 AM UTC, tony halik wrote:
Hi there, I checked your code using Bokeh 1.0.4 and it shows that it actually works: plotting stops after 10 steps
from bokeh.plotting import figure, curdoc
from bokeh.driving import linear
import random
p = figure(plot_width = 400, plot_height = 400)
r = p.line(, , color = “firebrick”, line_width = 2)
ds = r.data_source
@linear()
def update(step):
ds.data[‘x’].append(step)
ds.data[‘y’].append(random.randint(0, 100))
ds.trigger(‘data’, ds.data, ds.data)
if step == 10:
curdoc().remove_periodic_callback(pc_id)
curdoc().add_root(p)
pc_id = curdoc().add_periodic_callback(update, 1000)
``
On Wednesday, March 6, 2019 at 11:53:38 PM UTC+1, Kaushik Mallick wrote:
I am running a bokeh server app which uses a streaming dataset. Lets use a simple example
from bokeh.plotting import figure, curdoc
from bokeh.driving import linear
import random
p = figure(plot_width=400, plot_height=400)
r = p.line(, , color=“firebrick”, line_width=2)
ds = r.data_source
@linear()
def update(step):
ds.data[‘x’].append(step)
ds.data[‘y’].append(random.randint(0,100))
ds.trigger(‘data’, ds.data, ds.data)
curdoc().add_root(p)
Add a periodic callback to be run every 500 milliseconds
curdoc().add_periodic_callback(update, 500)
``
I would like to stop the streaming and plotting after a certain point (when x =10). How do I do that? I tried using remove_periodic_callback(update) but it does not work from within the callback function.