On May 9, 2018, at 02:33, Artur Scholz <[email protected]> wrote:
Thanks. I was referring to embedded server only. And my question was on how to add applications
afterwards, i.e. after having passed the applications dict to the bokeh server instantiation.
After reading through the docs and code, I am convinced that is not possible in that way.
So instead, rather than using one bokeh server and adding applications on the fly, I create one
dedicated embedded bokeh server for each application at startup, each at a distinct port.
server.py:
from threading import Thread, Lock
import socket
from bokeh.server.server import Server
from bokeh.embed import server_document
from tornado.ioloop import IOLoop
mutex = Lock()
def get_free_tcp_port():
tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp.bind(('', 0))
addr, port = tcp.getsockname()
tcp.close()
return port
class BokehServer:
"""Bokeh server (based on Tornado HTTPServer) to synchronize client and server
documents via websocket.
"""
def __init__(self, application, websocket_origin=['*']):
if not callable(application):
raise ValueError()
self.application = application
self.websocket_origin = websocket_origin
self.thread = Thread(target=self._server_thread)
self.thread.start()
def _server_thread(self):
self.io_loop = IOLoop()
with mutex:
self.port = get_free_tcp_port()
self.server = Server(
self.application, io_loop=self.io_loop,
allow_websocket_origin=self.websocket_origin,
port=self.port)
self.server.start()
self.server.io_loop.start()
def get_script(self):
return server_document('http://localhost:' + str(self.port))
view.py
def plot(doc):
# ... create a bokeh figure and add as root element to doc
server = server.BokehServer(plot)
@demo.route('/domain/demo/view/demo-plot')
def view_demo_plot():
script = server.get_script()
return render_template('demo/plot.html', script=script)
On Tue, May 8, 2018 at 3:41 PM, hyamanieu <[email protected]> wrote:
To answer your first question, you can also simply call
bokeh serve path/to/app1 path/to/app2
As for your second question regarding the specific use of Server, you can see that in the docs (bokeh.server.server — Bokeh 3.3.2 Documentation) you pass a dictionary of applications. Just add them in the dictionary.
Le lundi 7 mai 2018 13:04:21 UTC+2, Artur Scholz a écrit :
Is it possible to add further applications (that is, bokeh documents) to a running bokeh server?
For example, consider the flask application with embedded bokeh server:
https://github.com/bokeh/bokeh/blob/0.12.15/examples/howto/server_embed/flask_embed.py
Namely, how to add further applications to the server created in this step:
server = Server({'/bkapp': modify_doc}, io_loop=IOLoop(), allow_websocket_origin=["localhost:8000"])
Artur
--
You received this message because you are subscribed to a topic in the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/HNsguacFpYA/unsubscribe\.
To unsubscribe from this group and all its topics, 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/764f822a-09a3-4bdb-9b12-ec0f98a1ccfb%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/CALqfExZgnqJ6172uVYg%3Dt47SYyRY_QJdSspB6qD2%2B4qk0T3jOA%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.