I have a function modify_doc
which returns a curdoc() session.
def modify_doc(document_session):
...code...
return document_session.add_root(layout)
It mostly working as expected, but wrapping it in Flask app.py has proven to be more difficult and I could use some feedback. My initial approach is to start a bokeh server on “/bokeh” and then the flask app picks it up on “/dashboard” from my understanding.
from flask import Flask, render_template
from bokeh.embed import server_document
from bokeh.server.server import Server
from dashboard import modify_doc
from tornado.ioloop import IOLoop
application = Flask(__name__)
@application.route("/dashboard")
def server():
tag = server_document(url=r'/bokeh', relative_urls=True)
return render_template('index.html', tag=tag)
def worker():
server = Server(
modify_doc,
prefix=r'/bokeh',
io_loop=IOLoop(),
allow_websocket_origin= ["localhost:5006"])
server.start()
server.io_loop.start()
from threading import Thread
Thread(target=worker).start()
if __name__ == "__main__":
application.run(port=5006, debug=True)
However, the servers start with python app.py
mostly fine, but the bokeh server gives an error “GET http://localhost:5000/bokeh/autoload.js?bokeh-autoload-element=1001&bokeh-app-path=/bokeh net::ERR_ABORTED 404 (NOT FOUND)” and traceback from terminal:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/bb/Documents/External Drive/19-10-25 preliminary project materials/source/app.py", line 23, in worker
allow_websocket_origin= ["localhost:5006"])
File "/Users/bb/Documents/External Drive/19-10-25 preliminary project materials/source/vm/lib/python3.7/site-packages/bokeh/server/server.py", line 393, in __init__
sockets, self._port = bind_sockets(self.address, self.port)
File "/Users/bb/Documents/External Drive/19-10-25 preliminary project materials/source/vm/lib/python3.7/site-packages/bokeh/server/util.py", line 66, in bind_sockets
ss = netutil.bind_sockets(port=port or 0, address=address)
File "/Users/bb/Documents/External Drive/19-10-25 preliminary project materials/source/vm/lib/python3.7/site-packages/tornado/netutil.py", line 174, in bind_sockets
sock.bind(sockaddr)
OSError: [Errno 48] Address already in use