callbacks#
Client-side interactivity.
- class Callback(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Base class for interactive callback.
Note
This is an abstract base class used to help organize the hierarchy of Bokeh model types. It is not useful to instantiate on its own.
- class CloseDialog(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Close a dialog box.
- dialog#
A dialog instance to close.
The behavior of this action depends on the configuration of the dialog, in particular
Dialog.close_actionproperty.
- class CustomJS(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Execute a JavaScript function.
Warning
The explicit purpose of this Bokeh Model is to embed raw JavaScript code for a browser to execute. If any part of the code is derived from untrusted user inputs, then you must take appropriate care to sanitize the user input prior to passing to Bokeh.
- classmethod from_file(path: PathLike, **args: Any) CustomJS[source]#
Construct a
CustomJSinstance from a*.jsor*.mjsfile.For example, if we want to construct a
CustomJSinstance from a JavaScript modulemy_module.mjs, that takes a single argumentsource, then we would use:
- args#
A mapping of names to Python objects. In particular those can be bokeh’s models. These objects are made available to the callback’s code snippet as the values of named parameters to the callback.
- code#
A snippet of JavaScript code to execute in the browser.
This can be interpreted either as a JavaScript function or a module, depending on the
moduleproperty:A JS function.
The code is made into the body of a function, and all of of the named objects in
argsare available as parameters that the code can use. Additionally, acb_objparameter contains the object that triggered the callback an optionalcb_dataparameter that contains any tool-specific data (i.e. mouse coordinates and hovered glyph indices for theHoverTool) and additional document context incb_contextargument.An ES module.
A JavaScript module (ESM) exporting a default function with the following signature:
where
argsis a key-value mapping of user-provided parameters,objrefers to the object that triggered the callback,datais a key-value mapping of optional parameters provided by the caller, andcontextis an additional document context.The additional document context is composed of the following members:
index: The view manager governing all views in the current instance ofBokeh. If only one instance ofBokehis loaded, then this is equivalent to usingBokeh.index.
This function can be an asynchronous function (
async function () {}orasync () => {}) if for example external resources are needed, which would require usage of one of the asynchronous Web APIs, for example:
- module#
Whether to interpret the code as a JS function or ES module. If set to
"auto", the this will be inferred from the code.
- class OpenDialog(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Open a dialog box.
- dialog#
A dialog instance to open.
This will either build and display an new dialog view or re-open an existing dialog view if it was hidden.
Note
To display multiple instances of dialog, one needs to clone the dialog’s model and use another instance of
OpenDialog.
- class OpenURL(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Open a URL in a new or current tab or window.
- same_tab#
Open URL in a new (False, default) or current (True) tab or window. For same_tab=False, whether tab or window will be opened is browser dependent.
- url#
The URL to direct the web browser to. This can be a template string, which will be formatted with data from the data source.