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_action property.

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 CustomJS instance from a *.js or *.mjs file.

For example, if we want to construct a CustomJS instance from a JavaScript module my_module.mjs, that takes a single argument source, 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 module property:

  1. A JS function.

The code is made into the body of a function, and all of of the named objects in args are available as parameters that the code can use. Additionally, a cb_obj parameter contains the object that triggered the callback an optional cb_data parameter that contains any tool-specific data (i.e. mouse coordinates and hovered glyph indices for the HoverTool) and additional document context in cb_context argument.

  1. An ES module.

A JavaScript module (ESM) exporting a default function with the following signature:

where args is a key-value mapping of user-provided parameters, obj refers to the object that triggered the callback, data is a key-value mapping of optional parameters provided by the caller, and context is 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 of Bokeh. If only one instance of Bokeh is loaded, then this is equivalent to using Bokeh.index.

This function can be an asynchronous function (async function () {} or async () => {}) 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.

class SetValue(*args: Any, id: ID | None = None, **kwargs: Any)[source]#

Allows to update a property of an object.

attr: str#

The property to modify.

obj: HasProps#

Object to set the value on.

value#

The value to set.

class ToggleVisibility(*args: Any, id: ID | None = None, **kwargs: Any)[source]#

Toggle visibility of a UI element.

target#

A UI element to show or hide.