Hi,
I don’t think this is possible, but it seems to me to be a useful feature.
Consider the case where we have a data stream, say weather data from a collection of sensors. The sensors are by location, so the data stream looks like:
(LONDON, 13.6)
(LONDON, 14.6)
(PARIS, 15.6)
(LONDON, 13.2)
Every time I see a new city, I’d like to create a new Bokeh application. One way to do this would be to use ‘bokeh serve’ to serve up a directory with one script per city - then I’d have the endpoints “/london”, “/paris” etc However, this is impractical if I don’t know how many cities I might be seeing in advance.
There are two possible improvements that might help.
- ‘Server side’ implementation
When a script is loaded using ‘bokeh serve’, that script could hook the bokeh.Server object and be able to add Applications (aka app_path) on the fly. It doesn’t appear this is currently possible, as the scripts are already considered applications, and have access to a limited API (namely ServerContext and SessionContext).
- ‘Client side’ implementation
It seems to me the best solution is to allow bokeh.client.push_session to specify a brand new app_path. Continuing the above example, pseudo code might look like:
city = LONDON # comes from data stream
if city not in city_dict: # if we have not seen the city before
document = Document() # TODO: populate the Document
update_document(document) # Update the document with the latest data
session = push_session(document, app_path='/'+city) # We now have a new server endpoint: '/LONDON'
else:
session = city_dict[city] # we've seen this city before: we already have a session
update_document(session.document) # Update the document with the latest data
In practice, create applications on the fly would probably need a separate api (although the above could be a short-cut for a common case), something like:
ClientServerContext:
GetApplications() # Get a list of application instances
CreateApplication(app_path) # Create a new application, served at the given app_path
GetApplication(app_path) # Get the application served on the given app_path
I’m going to take a look at hacking up bokeh.Server to see if I can’t get something working, and will post my learnings.
Regards,
Josh.