bokeh.document.events (original) (raw)
Provide events that represent various changes to Bokeh Documents.
These events are used internally to signal changes to Documents. For information about user-facing (e.g. UI or tool) events, see the reference for bokeh.events.
These events are employed for incoming and outgoing websocket messages and internally for triggering callbacks. For example, the sequence of events that happens when a user calls a Document API or sets a property resulting in a “patch event” to the Document:
user invokes Document API -> Document API triggers event objects -> registered callbacks are executed -> Session callback generates JSON message from event object -> Session sends JSON message over websocket
But events may also be triggered from the client, and arrive as JSON messages over the transport layer, which is why the JSON handling and Document API must be separated. Consider the alternative sequence of events:
Session receives JSON message over websocket -> Document calls event.handle_json -> handle_json invokes appropriate Document API -> Document API triggers event objects -> registered callbacks are executed -> Session callback suppresses outgoing event
As a final note, message “ping-pong” is avoided by recording a “setter” when events objects are created. If the session callback notes the event setter is itself, then no further action (e.g. sending an outgoing change event identical to the incoming event it just processed) is taken.
class ColumnDataChangedEvent(document: Document, model: Model, attr: str, data: DataDict | None = None, cols: list[str] | None = None, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
A concrete event representing efficiently replacing _all_existing data for a ColumnDataSource
__init__(document: Document, model: Model, attr: str, data: DataDict | None = None, cols: list[str] | None = None, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
Parameters:
- document (Document) – A Bokeh document that is to be updated.
- column_source (ColumnDataSource)
- cols (list_[_str]) – optional explicit list of column names to update. If None, all columns will be updated (default: None)
- setter (ClientSession or ServerSession or None , optional) –
This is used to prevent “boomerang” updates to Bokeh apps. (default: None)
See DocumentChangedEventfor more details. - callback_invoker (callable , optional) – A callable that will invoke any Model callbacks that should be executed in response to the change that triggered this event. (default: None)
dispatch(receiver: Any) → None[source]#
Dispatch handling of this event to a receiver.
This method will invoke receiver._column_data_changed
if it exists.
to_serializable(serializer: Serializer) → ColumnDataChanged[source]#
Create a JSON representation of this event suitable for sending to clients.
{ 'kind' : 'ColumnDataChanged' 'column_source' : 'data' : 'cols' : }
Parameters:
serializer (Serializer)
class ColumnsPatchedEvent(document: Document, model: Model, attr: str, patches: Patches, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
A concrete event representing efficiently applying data patches to a ColumnDataSource
__init__(document: Document, model: Model, attr: str, patches: Patches, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
Parameters:
- document (Document) – A Bokeh document that is to be updated.
- column_source (ColumnDataSource) – The data source to apply patches to.
- patches (list)
- setter (ClientSession or ServerSession or None , optional) –
This is used to prevent “boomerang” updates to Bokeh apps. (default: None)
See DocumentChangedEventfor more details. - callback_invoker (callable , optional) – A callable that will invoke any Model callbacks that should be executed in response to the change that triggered this event. (default: None)
dispatch(receiver: Any) → None[source]#
Dispatch handling of this event to a receiver.
This method will invoke receiver._columns_patched
if it exists.
to_serializable(serializer: Serializer) → ColumnsPatched[source]#
Create a JSON representation of this event suitable for sending to clients.
{ 'kind' : 'ColumnsPatched' 'column_source' : 'patches' : }
Parameters:
serializer (Serializer)
class ColumnsStreamedEvent(document: Document, model: Model, attr: str, data: DataDict | pd.DataFrame, rollover: int | None = None, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
A concrete event representing efficiently streaming new data to a ColumnDataSource
__init__(document: Document, model: Model, attr: str, data: DataDict | pd.DataFrame, rollover: int | None = None, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
Parameters:
- document (Document) – A Bokeh document that is to be updated.
- column_source (ColumnDataSource) – The data source to stream new data to.
- data (dict or DataFrame) –
New data to stream.
If a DataFrame, will be stored as{c: df[c] for c in df.columns}
- rollover (int, optional) – A rollover limit. If the data source columns exceed this limit, earlier values will be discarded to maintain the column length under the limit.
- setter (ClientSession or ServerSession or None , optional) –
This is used to prevent “boomerang” updates to Bokeh apps. (default: None)
See DocumentChangedEventfor more details. - callback_invoker (callable , optional) – A callable that will invoke any Model callbacks that should be executed in response to the change that triggered this event. (default: None)
dispatch(receiver: Any) → None[source]#
Dispatch handling of this event to a receiver.
This method will invoke receiver._columns_streamed
if it exists.
to_serializable(serializer: Serializer) → ColumnsStreamed[source]#
Create a JSON representation of this event suitable for sending to clients.
{ 'kind' : 'ColumnsStreamed' 'column_source' : 'data' : 'rollover' : }
Parameters:
serializer (Serializer)
class DocumentChangedEvent(document: Document, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
Base class for all internal events representing a change to a Bokeh Document.
__init__(document: Document, setter: Setter | None = None, callback_invoker: Invoker | None = None) → None[source]#
Parameters:
- document (Document) – A Bokeh document that is to be updated.
- setter (ClientSession or ServerSession or None , optional) –
This is used to prevent “boomerang” updates to Bokeh apps. (default: None)
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself. - callback_invoker (callable , optional) – A callable that will invoke any Model callbacks that should be executed in response to the change that triggered this event. (default: None)
combine(event: DocumentChangedEvent) → bool[source]#
dispatch(receiver: Any) → None[source]#
Dispatch handling of this event to a receiver.
This method will invoke receiver._document_changed
if it exists.
class DocumentPatchedEvent(document: Document, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
A Base class for events that represent updating Bokeh Models and their properties.
dispatch(receiver: Any) → None[source]#
Dispatch handling of this event to a receiver.
This method will invoke receiver._document_patched
if it exists.
static handle_event(doc: Document, event_rep: DocumentPatched, setter: Setter | None) → None[source]#
to_serializable(serializer: Serializer) → MessageSent | ModelChanged | ColumnDataChanged | ColumnsStreamed | ColumnsPatched | TitleChanged | RootAdded | RootRemoved[source]#
Create a JSON representation of this event suitable for sending to clients.
Sub-classes must implement this method.
Parameters:
serializer (Serializer)
class MessageSentEvent(document: Document, msg_type: str, msg_data: Any | bytes, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
dispatch(receiver: Any) → None[source]#
Dispatch handling of this event to a receiver.
This method will invoke receiver._document_patched
if it exists.
to_serializable(serializer: Serializer) → MessageSent[source]#
Create a JSON representation of this event suitable for sending to clients.
Sub-classes must implement this method.
Parameters:
serializer (Serializer)
class ModelChangedEvent(document: Document, model: Model, attr: str, new: Any, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
A concrete event representing updating an attribute and value of a specific Bokeh Model.
__init__(document: Document, model: Model, attr: str, new: Any, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
Parameters:
- document (Document) – A Bokeh document that is to be updated.
- model (Model) – A Model to update
- attr (str) – The name of the attribute to update on the model.
- new (object) – The new value of the attribute
- setter (ClientSession or ServerSession or None , optional) –
This is used to prevent “boomerang” updates to Bokeh apps. (default: None)
See DocumentChangedEventfor more details. - callback_invoker (callable , optional) – A callable that will invoke any Model callbacks that should be executed in response to the change that triggered this event. (default: None)
combine(event: DocumentChangedEvent) → bool[source]#
dispatch(receiver: Any) → None[source]#
Dispatch handling of this event to a receiver.
This method will invoke receiver._document_model_changed
if it exists.
to_serializable(serializer: Serializer) → ModelChanged[source]#
Create a JSON representation of this event suitable for sending to clients.
Parameters:
serializer (Serializer)
class RootAddedEvent(document: Document, model: Model, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
A concrete event representing a change to add a new Model to a Document’s collection of “root” models.
__init__(document: Document, model: Model, setter: Setter | None = None, callback_invoker: Invoker | None = None) → None[source]#
Parameters:
- document (Document) – A Bokeh document that is to be updated.
- model (Model) – The Bokeh Model to add as a Document root.
- setter (ClientSession or ServerSession or None , optional) –
This is used to prevent “boomerang” updates to Bokeh apps. (default: None)
See DocumentChangedEventfor more details. - callback_invoker (callable , optional) – A callable that will invoke any Model callbacks that should be executed in response to the change that triggered this event. (default: None)
to_serializable(serializer: Serializer) → RootAdded[source]#
Create a JSON representation of this event suitable for sending to clients.
{ 'kind' : 'RootAdded' 'title' : }
Parameters:
serializer (Serializer)
class RootRemovedEvent(document: Document, model: Model, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
A concrete event representing a change to remove an existing Model from a Document’s collection of “root” models.
__init__(document: Document, model: Model, setter: Setter | None = None, callback_invoker: Invoker | None = None) → None[source]#
Parameters:
- document (Document) – A Bokeh document that is to be updated.
- model (Model) – The Bokeh Model to remove as a Document root.
- setter (ClientSession or ServerSession or None , optional) –
This is used to prevent “boomerang” updates to Bokeh apps. (default: None)
See DocumentChangedEventfor more details. - callback_invoker (callable , optional) – A callable that will invoke any Model callbacks that should be executed in response to the change that triggered this event. (default: None)
to_serializable(serializer: Serializer) → RootRemoved[source]#
Create a JSON representation of this event suitable for sending to clients.
{ 'kind' : 'RootRemoved' 'title' : }
Parameters:
serializer (Serializer)
class SessionCallbackAdded(document: Document, callback: SessionCallback)[source]#
A concrete event representing a change to add a new callback (e.g. periodic, timeout, or “next tick”) to a Document.
__init__(document: Document, callback: SessionCallback) → None[source]#
Parameters:
- document (Document) – A Bokeh document that is to be updated.
- callback (SessionCallback) – The callback to add
dispatch(receiver: Any) → None[source]#
Dispatch handling of this event to a receiver.
This method will invoke receiver._session_callback_added
if it exists.
class SessionCallbackRemoved(document: Document, callback: SessionCallback)[source]#
A concrete event representing a change to remove an existing callback (e.g. periodic, timeout, or “next tick”) from a Document.
__init__(document: Document, callback: SessionCallback) → None[source]#
Parameters:
- document (Document) – A Bokeh document that is to be updated.
- callback (SessionCallback) – The callback to remove
dispatch(receiver: Any) → None[source]#
Dispatch handling of this event to a receiver.
This method will invoke receiver._session_callback_removed
if it exists.
class TitleChangedEvent(document: Document, title: str, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
A concrete event representing a change to the title of a Bokeh Document.
__init__(document: Document, title: str, setter: Setter | None = None, callback_invoker: Invoker | None = None)[source]#
Parameters:
- document (Document) – A Bokeh document that is to be updated.
- title (str) – The new title to set on the Document
- setter (ClientSession or ServerSession or None , optional) –
This is used to prevent “boomerang” updates to Bokeh apps. (default: None)
See DocumentChangedEventfor more details. - callback_invoker (callable , optional) – A callable that will invoke any Model callbacks that should be executed in response to the change that triggered this event. (default: None)
combine(event: DocumentChangedEvent) → bool[source]#
to_serializable(serializer: Serializer) → TitleChanged[source]#
Create a JSON representation of this event suitable for sending to clients.
{ 'kind' : 'TitleChanged' 'title' : }
Parameters:
serializer (Serializer)