bokeh.application.handlers.directory

Provide a Bokeh Application Handler to build up documents by running the code from main.py or main.ipynb` files in specified directories.

The directory may also optionally contain:

  • A server_lifecyle.py module to provide lifecycle callbacks for the application and sessions.
  • A static subdirectory containing app-specific static resources to serve.
  • A theme.yaml file containing a Bokeh theme to automatically apply to all new documents.
  • A tempates subdirectory containing templates for app display

A full directory layout might look like:

myapp
   |
   +---main.py
   +---server_lifecycle.py
   +---static
   +---theme.yaml
   +---templates
        +---index.html
class DirectoryHandler(*args, **kwargs)[source]

Load an application directory which modifies a Document.

__init__(*args, **kwargs)[source]
modify_document(doc)[source]

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(server_context)[source]

Execute on_server_unloaded` from server_lifecycle.py (if it is defined) when the server is first started.

Parameters:server_context (ServerContext) –
on_server_unloaded(server_context)[source]

Execute on_server_unloaded from server_lifecycle.py (if it is defined) when the server cleanly exits. (Before stopping the server’s IOLoop.)

Parameters:server_context (ServerContext) –

Warning

In practice this code may not run, since servers are often killed by a signal.

on_session_created(session_context)[source]

Execute on_session_created from server_lifecycle.py (if it is defined) when a new session is created.

Parameters:session_context (SessionContext) –
on_session_destroyed(session_context)[source]

Execute on_session_destroyed from server_lifecycle.py (if it is defined) when a session is destroyed.

Parameters:session_context (SessionContext) –
url_path()[source]

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

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.