python - How to correctly deploy Bokeh app requiring server callbacks? -


i want use bokeh server persist plot , data, can embed bokeh app in website. i'm trying recreate example given on bokeh 0.12.6 documentation:

from bokeh.client import push_session bokeh.embed import autoload_server bokeh.plotting import figure, curdoc  # figure() function auto-adds figure curdoc() plot = figure() plot.circle([1,2], [3,4])  session = push_session(curdoc()) script = autoload_server(plot, session_id=session.id) 

so i'm starting bokeh server , running python program such:

bokeh serve --show animated.py 

the error i'm getting looks this:

file "session.py", line 298, in push: raise ioerror("cannot push session document because failed connect server (to start server, try 'bokeh serve' command)") traceback (most recent call last): file "/users/.../anaconda/lib/python3.5/site-packages/bokeh/application/handlers/code_runner.py", line 81, in run exec(self._code, module.__dict__) file "/users/.../documents/.../.../animated.py", line 9, in <module> session = push_session(curdoc()) file "/users/.../anaconda/lib/python3.5/site-packages/bokeh/client/session.py", line 86, in push_session session.push(document) file "/users/.../anaconda/lib/python3.5/site-packages/bokeh/client/session.py", line 298, in push raise ioerror("cannot push session document because failed connect server (to start server, try 'bokeh serve' command)") oserror: cannot push session document because failed connect server (to start server, try 'bokeh serve' command) 

how should go fixing problem? , if autoload_server() wrong approach, other ways deploy bokeh app?

you'll want bokeh app looking like:

### contents of app.py  bokeh.client import push_session bokeh.embed import server_document bokeh.plotting import figure, curdoc  plot = figure() plot.circle([1,2], [3,4])  doc = curdoc() doc.add_root(plot) 

you'll serve via: (you may not need origin kwarg, ymmv)

bokeh serve app.py --allow-websocket-origin="*" 

knowing server app running @ http://localhost:5006/ss (or whatever terminal running app says), create script load there via

script = autoload_server(url='http://localhost:5006/ss') # or whatever location of server process is. 

the embed script in webpage somehow (perhaps loading script jinja template), here it's copy pasted basic html template:

<!doctype html>  <html lang="en"> <head> </head>  <body>   <script       src="http://localhost:5006/ss/autoload.js?bokeh-autoload-element=435ac063-5288-41b9-8375-31907dd5f124&bokeh-app-path=/ss&bokeh-absolute-url=http://localhost:5006/ss"       id="435ac063-5288-41b9-8375-31907dd5f124"       data-bokeh-model-id=""       data-bokeh-doc-id=""></script> </body> </html> 

opening above html doc should open page plot.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -