bokeh.application.handlers.script#

Provide a Bokeh Application Handler to build up documents by running the code from Python script (.py) files.

This handler is configured with the filename of a Python module. When a Bokeh application calls modify_doc, the contents of the module are run to process a new Document for a session. When the script code is executed, the Document being modified will be available as curdoc, and any optionally provided args will be available as sys.argv.

As an example, consider the following Python module myapp.py

# myapp.py

import sys

from bokeh.io import cudoc
from bokeh.plotting import figure

p = figure(x_range=(10, 10), y_range=(10, 10), title=sys.argv[1])

curdoc().add_root(p)

The a ScriptHandler configured with this script will modify new Bokeh Documents by adding an empty plot with a title taken from args.

class ScriptHandler(*, filename: PathLike, argv: list[str] = [], package: ModuleType | None = None)[source]#

Modify Bokeh documents by executing code from Python scripts.

Public Data Attributes:

Inherited from : py: class:CodeHandler

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.

Inherited from : py: class:Handler

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.

Public Methods:

__init__(*, filename[, argv, package])

Keywords:

Inherited from : py: class:CodeHandler

__init__(*, filename[, argv, package])

Keywords:

modify_document(doc)

Run Bokeh application code to update a Document

url_path()

The last path component for the basename of the configured filename.

Inherited from : py: class:Handler

__init__(*, filename[, argv, package])

Keywords:

modify_document(doc)

Run Bokeh application code to update a Document

on_server_loaded(server_context)

Execute code when the server is first started.

on_server_unloaded(server_context)

Execute code when the server cleanly exits.

on_session_created(session_context)

Execute code when a new session is created.

on_session_destroyed(session_context)

Execute code 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 configured filename.


__init__(*, filename: PathLike, argv: list[str] = [], package: ModuleType | None = None) None[source]#
Keywords:

filename (str) : a path to a Python source (“.py”) file