Unfortunately the example in the pastebin is far too large and complicated to dig deeply into, it would take several hours at least just to try and tease out the relevant Bokeh parts from the domain-specific bits. However I was able to quickly create to a minimal app that I believe distills all the relevant Bokeh functionality you are looking for: every once in a while, stream a new "last" point, and in between those times, also update the last point in place. It's often good to start from a small working example and build up from there, so I hope this will be useful to you in that regard.
from functools import partial
from random import random
from threading import Thread
from bokeh.models import ColumnDataSource
from bokeh.plotting import curdoc, figure
from tornado import gen
# this must only be modified from a Bokeh session allback
source = ColumnDataSource(data=dict(x=, y=))
# This is important! Save curdoc() to make sure all threads
# see then same document.
doc = curdoc()
idx = 0
count = 0
def stream_update(x, y):
source.stream(dict(x=, y=[y]), rollover=500)
def patch_update(idx, y):
global count, idx
y = random()
# every fifth update, stream a new last point
if count % 5 == 0:
idx += 1
x = idx/2.0
doc.add_next_tick_callback(partial(stream_update, x=x, y=y))
# other times, update the existing last point
doc.add_next_tick_callback(partial(patch_update, idx=idx, y=y))
p = figure(y_range=[0,1])
l = p.circle(x='x', y='y', size=10, source=source)
thread = Thread(target=blocking_task)
On Sep 1, 2016, at 12:10 PM, [email protected]l.com wrote:
As proof-of-concept I've created an ohlc_RT demonstration piece which updates in real time with fractally synthesised ohlc data. I'm having issues with the stream and patch calls. The code contains a Chart class which upon instantiation plots a chunk of fractal synthesised ohlc historical data to the chart; next as real time data is received and a candlestick closes then it is streamed to the Bokeh server. The first call to stream will plot and extend the output on the chart but after that their is no further streaming. I haven't seen patch operate yet. It runs using 'bokeh serve --show ohlc_RT' like the other Bokeh examples. I suspect that something is not correct in my implementation of add_next_tick_callback()
Anyone have any tips to get this working as intended?
On Wednesday, 24 August 2016 14:40:31 UTC+1, Bryan Van de ven wrote:
To handle external async events (e.g. updates from Redis or a ZMQ socket handler, or whatever) you'll want to fillow the same general advice in the "Updating From Threads" section of the User's Guide:
Which is to say, whatever event handler receives the new data, it should schedule a "next_tick_callback" to safely modify the Bokeh document from.
> On Aug 24, 2016, at 8:27 AM, GoFaster <[email protected]> wrote:
> In the Bokeh streaming ohlc example this line;
> curdoc().add_periodic_callback(update, 50)
> is used to generate synthetic data and update the Bokeh server plot on a timed callback every 50 milliseconds.
> In the real world the plot would need to be updated as-and-when new data arrived from the market. What Bokeh commands/calls could be used to send new data updates to the plot/server in an event driven manner?
> def market_update(dt, o, h, l, c):
> new_data = dict(
> curdoc().update_and_display_modified_plot(new_data) # I made this up
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/27fa0685-a579-4708-a95a-7e26b66dc3e5%40continuum.io.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout.
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/035a21cd-0329-49c2-8497-c52ad6fd664b%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.