I did find this example
and modified the code so that data is being pushed to the client rather than pulled.
When I run this i get the error:
Exception in thread Thread-1:
Traceback (most recent call last):
File “/Users/Jg/anaconda3431/lib/python3.6/threading.py”, line 916, in _bootstrap_inner
self.run()
File “/Users/Jg/anaconda3431/lib/python3.6/threading.py”, line 864, in run
self._target(*self._args, **self._kwargs)
File “tornado_embed.py”, line 43, in threaded_function
source.data = ColumnDataSource(data=data).data
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/core/has_props.py”, line 263, in setattr
super(HasProps, self).__setattr__(name, value)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/core/property/descriptors.py”, line 931, in set
self._internal_set(obj, value, hint=hint, setter=setter)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/core/property/descriptors.py”, line 727, in _internal_set
self._real_set(obj, old, value, hint=hint, setter=setter)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/core/property/descriptors.py”, line 796, in _real_set
self._trigger(obj, old, value, hint=hint, setter=setter)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/core/property/descriptors.py”, line 873, in _trigger
obj.trigger([self.name](http://self.name), old, value, hint, setter)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/model.py”, line 549, in trigger
super(Model, self).trigger(attr, old, new, hint=hint, setter=setter)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/util/callback_manager.py”, line 120, in trigger
self._document._notify_change(self, attr, old, new, hint, setter, invoke)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/document/document.py”, line 941, in _notify_change
self._trigger_on_change(event)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/document/document.py”, line 1049, in _trigger_on_change
self._with_self_as_curdoc(invoke_callbacks)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/document/document.py”, line 1062, in _with_self_as_curdoc
return f()
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/document/document.py”, line 1048, in invoke_callbacks
cb(event)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/document/document.py”, line 614, in
self._callbacks[receiver] = lambda event: event.dispatch(receiver)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/document/events.py”, line 195, in dispatch
super(ModelChangedEvent, self).dispatch(receiver)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/document/events.py”, line 77, in dispatch
receiver._document_patched(self)
File “/Users/Jg/anaconda3431/lib/python3.6/site-packages/bokeh/server/session.py”, line 180, in _document_patched
raise RuntimeError("_pending_writes should be non-None when we have a document lock, and we should have the lock when the document changes")
RuntimeError: _pending_writes should be non-None when we have a document lock, and we should have the lock when the document changes
What am I doing wrong here?
Code is:
from jinja2 import Environment, FileSystemLoader
from tornado.web import RequestHandler
from bokeh.embed import server_document
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure
from bokeh.server.server import Server
from bokeh.themes import Theme
from bokeh.sampledata.sea_surface_temperature import sea_surface_temperature
#from threading import Thread
import threading
from time import sleep
env = Environment(loader=FileSystemLoader(‘templates’))
class IndexHandler(RequestHandler):
def get(self):
template = env.get_template(‘embed.html’)
script = server_document(‘http://localhost:5006/bkapp’)
self.write(template.render(script=script, template=“Tornado”))
def modify_doc(doc):
df = sea_surface_temperature.copy()
source = ColumnDataSource(data=df)
plot = figure(x_axis_type=‘datetime’, y_range=(0, 25), y_axis_label=‘Temperature (Celsius)’,
title=“Sea Surface Temperature at 43.18, -70.43”)
plot.line(‘time’, ‘temperature’, source=source)
def threaded_function():
sleep(3)
for new in range(20):
print(new)
if new == 0:
data = df
else:
data = df.rolling(‘{0}D’.format(new)).mean()
source.data = ColumnDataSource(data=data).data
sleep(1)
slider = Slider(start=0, end=30, value=0, step=1, title=“Smoothing by N Days”)
#slider.on_change(‘value’, callback)
doc.add_root(column(slider, plot))
doc.theme = Theme(filename=“theme.yaml”)
tf = threading.Thread(target=threaded_function)
tf.start()
Setting num_procs here means we can’t touch the IOLoop before now, we must
let Server handle that. If you need to explicitly handle IOLoops then you
will need to use the lower level BaseServer class.
server = Server({‘/bkapp’: modify_doc}, num_procs=4, extra_patterns=[(‘/’, IndexHandler)])
server.start()
if name == ‘main’:
from bokeh.util.browser import view
print(‘Opening Tornado app with embedded Bokeh application on http://localhost:5006/’)
server.io_loop.add_callback(view, “http://localhost:5006/”)
server.io_loop.start()
···
On Mon, Jul 30, 2018 at 5:37 PM, Bokeh coder [email protected] wrote:
Hi, is there anywhere any example of how to run bokeh server with a stream to the client in a custom tornado server fashion which works on 0.13.0?
I find the docs on how to do this a bit difficult to read and I dont understand how to get started on this - so an example would be wonderful.
Thanks
–
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/cb17001b-e2ca-4085-b62a-7726bfe95a1f%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.