bokeh.model#
- class Model(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Base class for all objects stored in Bokeh
Documentinstances.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.
- classmethod clear_extensions() None[source]#
Clear any currently defined custom extensions.
Serialization calls will result in any currently defined custom extensions being included with the generated Document, whether or not there are utilized. This method can be used to clear out all existing custom extension definitions.
- classmethod parameters() list[Parameter][source]#
Generate Python
Parametervalues suitable for functions that are derived from the glyph.- Returns:
list(Parameter)
- js_link(attr: str, other: Model, other_attr: str, attr_selector: int | str | None = None) None[source]#
Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a
CustomJScallback to update one Bokeh model property whenever another changes value.- Parameters:
Added in version 1.1
- Raises:
Examples
This code with
js_link:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
- js_on_change(event: str, *callbacks: JSChangeCallback) None[source]#
Attach a
CustomJScallback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name". As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource, use the"stream"event on the source:source.js_on_change('streaming', callback)
- on_change(attr: str, *callbacks: PropertyCallback) None[source]#
Add a callback on this object to trigger when
attrchanges.- Parameters:
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns:
None
Examples
widget.on_change('value', callback1, callback2, ..., callback_n)
- select(selector: SelectorType) Iterable[Model][source]#
Query this object and all of its references for objects that match the given selector.
- Parameters:
selector (JSON-like)
- Returns:
seq[Model]
- select_one(selector: SelectorType) Model | None[source]#
Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns:
Model
- set_select(selector: type[Model] | SelectorType, updates: dict[str, Any]) None[source]#
Update objects that match a given selector with the specified attribute/value updates.
- Parameters:
selector (JSON-like)
updates (dict)
- Returns:
None
- to_serializable(serializer: Serializer) ObjectRefRep[source]#
Converts this object to a serializable representation.
- trigger(attr: str, old: Any, new: Any, hint: DocumentPatchedEvent | None = None, setter: Setter | None = None) None[source]#
- js_event_callbacks#
A mapping of event names to lists of
CustomJScallbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_eventmethod:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
- js_property_callbacks#
A mapping of attribute names to lists of
CustomJScallbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_changemethod:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
- name#
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.scatter([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
- subscribed_events#
Collection of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
- syncable: bool#
Indicates whether this model should be synchronized back to a Bokeh server when updated in a web browser. Setting to
Falsemay be useful to reduce network traffic when dealing with frequently updated objects whose updated values we don’t need.Note
Setting this property to
Falsewill prevent anyon_change()callbacks on this object from triggering. However, any JS-side callbacks will still work.
- tags#
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.scatter([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJScallbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
- collect_models(*input_values: Any) list[Model][source]#
Collect a duplicate-free list of all other Bokeh models referred to by this model, or by any of its references, etc.
Iterate over
input_valuesand descend through their structure collecting all nestedModelson the go. The resulting list is duplicate-free based on objects’ identifiers.
- get_class(view_model_name: str) type[Model][source]#
Look up a Bokeh model class, given its view model name.
- Parameters:
view_model_name (str) – A view model name for a Bokeh model to look up
- Returns:
the model class corresponding to
view_model_name- Return type:
- Raises:
KeyError, if the model cannot be found –
Example
>>> from bokeh.model import get_class >>> get_class("Range1d") <class 'bokeh.models.ranges.Range1d'>