How to serve multiple bokeh.application.Application instances in one tornado loop?

Currently, I serve a single bokeh Application instance as follows:

handler = FunctionHandler(app_function)
bokeh_app = Application(handler)
bokeh_server = Server({'/': bokeh_app}, port=5006, io_loop=tornado.ioloop.IOLoop.current())

Is it possible to create multiple bokeh.application.Application instances based on a regex path, in the same way as in the following code?

class CdsHandler(tornado.web.RequestHandler):

rest_app = tornado.web.Application([
    (r"/(\w+)/(data|cfg|layout)/(\w+)", CdsHandler, dict(state=state))

I would like to have a bokeh server instance be able to provide the same functionality but to multiple browser tabs / uris. This would be much easier than launching a separate instance and have to choose different free ports each time.

Thanks in advance!

I don’t see why the route couldn’t be a regex but I’ve also never personally tried that (and no one has ever asked before). Have you made an attempt, and it didn’t work?

1 Like

I beg your pardon - it does work. My first attempt was using the capture expression (\w+) rather than the uncaptured one \w+. The uncaptured one works fine.

from tornado.ioloop import IOLoop
from bokeh.server.server import Server
from bokeh.application import Application
from bokeh.application.handlers.function import FunctionHandler
from bokeh.plotting import figure

def app_function(doc):
    path = doc.session_context.request.path
    fig = figure(title=path)

handler = FunctionHandler(app_function)
app = Application(handler)

# With the capture expression it does not work
# server = Server({r"/(\w+)": app}, port=5006, io_loop=IOLoop.current())

# This works however.  Can be accessed as:  http://locahost:5006/some_name
# and will then display 'some_name' as the title of the figure
server = Server({r"/\w+": app}, port=5006, io_loop=IOLoop.current())
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.