Provide a Bokeh Application Handler to build up documents by running the code from main.py or main.ipynb files in specified directories.
main.py
main.ipynb
The directory may also optionally contain:
A server_lifecyle.py module to provide lifecycle callbacks for the application and sessions.
server_lifecyle.py
A static subdirectory containing app-specific static resources to serve.
static
A theme.yaml file containing a Bokeh theme to automatically apply to all new documents.
theme.yaml
A templates subdirectory containing templates for app display
templates
A full directory layout might look like:
myapp | +---main.py +---server_lifecycle.py +---static +---theme.yaml +---templates +---index.html
DirectoryHandler
Load an application directory which modifies a Document.
__init__
filename (str) : a path to an application directory with either “main.py” or “main.ipynb”
argv (list[str], optional) : a list of string arguments to make available as sys.argv to main.py
modify_document
Execute the configured main.py or main.ipynb to modify the document.
This method will also search the app directory for any theme or template files, and automatically configure the document with them if they are found.
on_server_loaded
Execute on_server_unloaded` from server_lifecycle.py (if it is defined) when the server is first started.
server_lifecycle.py
server_context (ServerContext) –
on_server_unloaded
Execute on_server_unloaded from server_lifecycle.py (if it is defined) when the server cleanly exits. (Before stopping the server’s IOLoop.)
IOLoop
Warning
In practice this code may not run, since servers are often killed by a signal.
on_session_created
Execute on_session_created from server_lifecycle.py (if it is defined) when a new session is created.
session_context (SessionContext) –
on_session_destroyed
Execute on_session_destroyed from server_lifecycle.py (if it is defined) when a session is destroyed.
process_request
Processes incoming HTTP request returning a dictionary of additional data to add to the session_context.
request – HTTP request
A dictionary of JSON serializable data to be included on the session context.
url_path
The last path component for the basename of the path to the configured directory.
error
If the handler fails, may contain a related error message.
error_detail
If the handler fails, may contain a traceback or other details.
failed
True if the handler failed to modify the doc
True
safe_to_fork
Whether it is still safe for the Bokeh server to fork new workers.
False if the configured code (script, notebook, etc.) has already been run.
False