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
templates
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(*, filename: Union[str, os.PathLike[str]], argv: List[str] = [])[source]¶
Load an application directory which modifies a Document.
Public Data Attributes:
If the handler fails, may contain a related error message.
If the handler fails, may contain a traceback or other details.
True
if the handler failed to modify the docWhether it is still safe for the Bokeh server to fork new workers.
Inherited from
Handler
If the handler fails, may contain a related error message.
If the handler fails, may contain a traceback or other details.
True
if the handler failed to modify the docWhether it is still safe for the Bokeh server to fork new workers.
Public Methods:
__init__
(*, filename[, argv])Keywords:
modify_document
(doc)Execute the configured
main.py
ormain.ipynb
to modify the document.on_server_loaded
(server_context)Execute on_server_unloaded` from
server_lifecycle.py
(if it is defined) when the server is first started.on_server_unloaded
(server_context)Execute
on_server_unloaded
fromserver_lifecycle.py
(if it is defined) when the server cleanly exits.on_session_created
(session_context)Execute
on_session_created
fromserver_lifecycle.py
(if it is defined) when a new session is created.on_session_destroyed
(session_context)Execute
on_session_destroyed
fromserver_lifecycle.py
(if it is defined) when a session is destroyed.process_request
(request)Processes incoming HTTP request returning a dictionary of additional data to add to the session_context.
url_path
()The last path component for the basename of the path to the configured directory.
Inherited from
Handler
__init__
(*, filename[, argv])Keywords:
modify_document
(doc)Execute the configured
main.py
ormain.ipynb
to modify the document.on_server_loaded
(server_context)Execute on_server_unloaded` from
server_lifecycle.py
(if it is defined) when the server is first started.on_server_unloaded
(server_context)Execute
on_server_unloaded
fromserver_lifecycle.py
(if it is defined) when the server cleanly exits.on_session_created
(session_context)Execute
on_session_created
fromserver_lifecycle.py
(if it is defined) when a new session is created.on_session_destroyed
(session_context)Execute
on_session_destroyed
fromserver_lifecycle.py
(if it is defined) when a session is destroyed.process_request
(request)Processes incoming HTTP request returning a dictionary of additional data to add to the session_context.
static_path
()Return a path to app-specific static resources, if applicable.
url_path
()The last path component for the basename of the path to the configured directory.
- __init__(*, filename: Union[str, os.PathLike[str]], argv: List[str] = []) None [source]¶
- Keywords:
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(doc: bokeh.document.document.Document) None [source]¶
Execute the configured
main.py
ormain.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: bokeh.application.application.ServerContext) None [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: bokeh.application.application.ServerContext) None [source]¶
Execute
on_server_unloaded
fromserver_lifecycle.py
(if it is defined) when the server cleanly exits. (Before stopping the server’sIOLoop
.)- 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: bokeh.application.application.SessionContext) Coroutine[Any, Any, None] [source]¶
Execute
on_session_created
fromserver_lifecycle.py
(if it is defined) when a new session is created.- Parameters
session_context (SessionContext) –
- on_session_destroyed(session_context: bokeh.application.application.SessionContext) Coroutine[Any, Any, None] [source]¶
Execute
on_session_destroyed
fromserver_lifecycle.py
(if it is defined) when a session is destroyed.- Parameters
session_context (SessionContext) –
- process_request(request: tornado.httputil.HTTPServerRequest) Dict[str, Any] [source]¶
Processes incoming HTTP request returning a dictionary of additional data to add to the session_context.
- Parameters
request – HTTP request
- Returns
A dictionary of JSON serializable data to be included on the session context.