bokeh.application.handlers.code
Provide a Bokeh Application Handler to build up documents by compiling
and executing Python source code.
This Handler is used by the Bokeh server command line tool to build
applications that run off scripts and notebooks.
def make_doc(doc: Document):
# do work to modify the document, add plots, widgets, etc.
return doc
app = Application(FunctionHandler(make_doc))
server = Server({'/bkapp': app}, io_loop=IOLoop.current())
server.start()
-
class CodeHandler(*, source: str, filename: PathLike, argv: list[str] = [], package: ModuleType | None = None)[source]
Run source code which modifies a Document
-
__init__(*, source: str, filename: PathLike, argv: list[str] = [], package: ModuleType | None = None) → None[source]
- Parameters:
source (str) – python source code
filename (str) – a filename to use in any debugging or error output
argv (list[str], optional) – a list of string arguments to make
available as sys.argv when the code executes
-
modify_document(doc: Document) → None[source]
Run Bokeh application code to update a Document
- Parameters:
doc (Document) – a Document to update
-
url_path() → str | None[source]
The last path component for the basename of the configured filename.
-
property error: str | None
If the handler fails, may contain a related error message.
-
property error_detail: str | None
If the handler fails, may contain a traceback or other details.
-
property failed: bool
True if the handler failed to modify the doc
-
property safe_to_fork: bool
Whether it is still safe for the Bokeh server to fork new workers.
False if the code has already been executed.