Server Options
hover
creates abokeh
server app to deliver its annotation interface.This app can be served flexibly based on your needs.
Prerequisites
Suppose that we've already used a recipe
to create a handle
function like in the quickstart.
Recap from the tutorials before
- the
handle
is a function which renders plot elements on abokeh
document.
Option 1: Jupyter
We are probably familiar with this now:
from bokeh.io import show, output_notebook
output_notebook()
show(handle) # notebook_url='http://localhost:8888'
Pros & Cons
This inline Jupyter mode can integrate particularly well with your notebook workflow. For example, when your are (tentatively) done with annotation, the SupervisableDataset
can be accessed directly in the notebook, rather than exported to a file and loaded back.
The inline mode is highly recommended for local usage.
-
On the contrary, with a remote Jupyter server, it may have trouble displaying the plots.
- this can be due to failure of loading JavaScript libraries or accessing implicit bokeh server ports.
Option 2: Command Line
bokeh serve
starts an explicit tornado
server from the command line:
bokeh serve my-app.py
# my-app.py
# handle = ...
from bokeh.io import curdoc
doc = curdoc()
handle(doc)
Pros & Cons
This is the "classic" approach to run a bokeh
server. Remote access is simple through parameters specified here. The bokeh plot tools are mobile-friendly too -- this means you can host a server, e.g. an http-enabled cloud virtual machine, and annotate from a tablet.
The command line mode is less interactive, since Python objects in the script cannot be accessed on the fly.
Option 3: Anywhere in Python
It is possible to embed the app in regular Python:
from bokeh.server.server import Server
server = Server({'/my-app': handle})
server.start()
Pros & Cons
This embedded mode is a go-to for serving within a greater application.
Also note that each command line argument for bokeh serve
has a corresponding keyword argument to Server()
.
For instance, bokeh serve <args> --allow-websocket-origin=*
in the command line mirrors Server(*args, allow_websocket_origin='*')
in Python.
The embedded mode gives you the most control of your server.