Hi,
It looks like I need to document / explain some things better. First, the point of this kind of embedding is to be able to run it like a regular python script, e.g.:
python app.py
and NOT have to use "bokeh serve". This has been asked for by an number of folks. Next I need to explain that the function that gets passed to FunctionHandler needs to build the *entire* app, not just be one callback. With that in mind, here is your example updated to work. I had to make some small changes around the callback, since "global" does not have the same meaning for a function inside a function:
from bokeh.models import ColumnDataSource
import numpy as np
from bokeh.server.server import Server
from tornado.ioloop import IOLoop
from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
from bokeh.driving import count
io_loop = IOLoop.current()
def build_doc(doc):
source = ColumnDataSource(dict(x=, y=, avg=))
fig = figure()
fig.line(source=source, x='x', y='y', line_width=2, alpha=.85, color='red')
fig.line(source=source, x='x', y='avg', line_width=2, alpha=.85, color='blue')
@count()
def update_Data(ct):
sine = np.sin(ct)
sine_sum = sum(source.data['y']) + sine
new_data = dict(x=[ct], y=[sine], avg=[sine_sum/(ct+1)])
source.stream(new_data, 100)
doc.add_root(fig)
doc.add_periodic_callback(update_Data, 100)
bokeh_app = Application(FunctionHandler(build_doc))
server = Server({'/': bokeh_app}, io_loop=io_loop)
server.start()
if __name__ == '__main__':
print('Opening Bokeh application on http://localhost:5006/'\)
io_loop.add_callback(server.show, "/")
io_loop.start()
Thanks,
Bryan
···
On Jan 10, 2017, at 2:13 PM, Vivek Dwivedi <[email protected]> wrote:
I should also mention when I run the code below I do not get an error but my browser does not automatically launch and the data is not automatically streamed.
Thanks.
Code Below...
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, output_file, show
import numpy as np
from bokeh.server.server import Server
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler
from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
io_loop = IOLoop.current()
source = ColumnDataSource(dict(x = , y = , avg = ))
fig = figure()
fig.line(source=source, x='x', y='y', line_width = 2, alpha = .85, color ='red')
fig.line(source=source, x='x', y='avg', line_width = 2, alpha = .85, color ='blue')
ct = 0
sine_sum = 0
def update_Data(doc):
global ct, sine_sum
ct += 1
sine = np.sin(ct)
sine_sum += sine
new_data = dict(x = [ct], y = [sine], avg = [sine_sum/ct])
source.stream(new_data,100)
curdoc().add_root(fig)
curdoc().add_periodic_callback(update_Data,100)
bokeh_app = Application(FunctionHandler(update_Data))
server = Server({'/': bokeh_app}, io_loop=io_loop)
server.start()
#usage
#vivekd@Lumbergh:~/Desktop$ python -m bokeh serve --show main.py
if __name__ == '__main__':
print('Opening Bokeh application on http://localhost:5006/'\)
io_loop.add_callback(server.show, "/")
io_loop.start()
--
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/3d507311-1e73-4739-bb0f-4b669809beb5%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.