Provide the Document class, which is a container for Bokeh Models to be reflected to the client side BokehJS library.
Document
As a concrete example, consider a column layout with Slider and Select widgets, and a plot with some tools, an axis and grid, and a glyph renderer for circles. A simplified representation of this document might look like the figure below:
Slider
Select
A Bokeh Document is a collection of Bokeh Models (e.g. plots, tools, glyphs, etc.) that can be serialized as a single collection.¶
The basic unit of serialization for Bokeh.
Document instances collect Bokeh models (e.g. plots, layouts, widgets, etc.) so that they may be reflected into the BokehJS client runtime. Because models may refer to other models (e.g., a plot has a list of renderers), it is not generally useful or meaningful to convert individual models to JSON. Accordingly, the Document is thus the smallest unit of serialization for Bokeh.
add_next_tick_callback
Add callback to be invoked once on the next tick of the event loop.
callback (callable) – A callback function to execute on the next tick.
can be used with remove_next_tick_callback
remove_next_tick_callback
NextTickCallback
Note
Next tick callbacks only work within the context of a Bokeh server session. This function will no effect when Bokeh outputs to standalone HTML or Jupyter notebook cells.
add_periodic_callback
Add a callback to be invoked on a session periodically.
callback (callable) – A callback function to execute periodically
period_milliseconds (int) – Number of milliseconds between each callback execution.
can be used with remove_periodic_callback
remove_periodic_callback
PeriodicCallback
Periodic callbacks only work within the context of a Bokeh server session. This function will no effect when Bokeh outputs to standalone HTML or Jupyter notebook cells.
add_root
Add a model as a root of this Document.
Any changes to this model (including to other models referred to by it) will trigger on_change callbacks registered on this document.
on_change
model (Model) – The model to add as a root of this document.
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.
add_timeout_callback
Add callback to be invoked once, after a specified timeout passes.
callback (callable) – A callback function to execute after timeout
timeout_milliseconds (int) – Number of milliseconds before callback execution.
can be used with remove_timeout_callback
remove_timeout_callback
TimeoutCallback
Timeout callbacks only work within the context of a Bokeh server session. This function will no effect when Bokeh outputs to standalone HTML or Jupyter notebook cells.
apply_json_patch
Apply a JSON patch object and process any resulting events.
patch (JSON-data) – The JSON-object containing the patch to apply.
None
apply_json_patch_string
Apply a JSON patch provided as a string.
patch (str) –
clear
Remove all content from the document but do not reset title.
delete_modules
Clean up after any modules created by this Document when its session is destroyed.
from_json
Load a document from JSON.
A JSON-encoded document to create a new Document from.
from_json_string
A string with a JSON-encoded document to create a new Document from.
get_model_by_id
Find the model for the given ID in this document, or None if it is not found.
model_id (str) – The ID of the model to search for
Model or None
get_model_by_name
Find the model for the given name in this document, or None if it is not found.
name (str) – The name of the model to search for
hold
Activate a document hold.
While a hold is active, no model changes will be applied, or trigger callbacks. Once unhold is called, the events collected during the hold will be applied according to the hold policy.
unhold
hold ('combine' or 'collect', optional) –
Whether events collected during a hold should attempt to be combined (default: ‘combine’)
When set to 'collect' all events will be collected and replayed in order as-is when unhold is called.
'collect'
When set to 'combine' Bokeh will attempt to combine compatible events together. Typically, different events that change the same property on the same mode can be combined. For example, if the following sequence occurs:
'combine'
doc.hold('combine') slider.value = 10 slider.value = 11 slider.value = 12
Then only one callback, for the last slider.value = 12 will be triggered.
slider.value = 12
hold only applies to document change events, i.e. setting properties on models. It does not apply to events such as ButtonClick, etc.
ButtonClick
Provide callbacks to invoke if the document or any Model reachable from its roots changes.
on_session_destroyed
Provide callbacks to invoke when the session serving the Document is destroyed
Remove a callback added earlier with add_next_tick_callback.
callback_obj – a value returned from add_next_tick_callback
ValueError, if the callback was never added or has already been run or removed –
remove_on_change
Remove a callback added earlier with on_change.
KeyError, if the callback was never added –
Remove a callback added earlier with add_periodic_callback
callback_obj – a value returned from add_periodic_callback
ValueError, if the callback was never added or has already been removed –
remove_root
Remove a model as root model from this Document.
Changes to this model may still trigger on_change callbacks on this document, if the model is still referred to by other root models.
Remove a callback added earlier with add_timeout_callback.
callback_obj – a value returned from add_timeout_callback
replace_with_json
Overwrite everything in this document with the JSON-encoded document.
A JSON-encoded document to overwrite this one.
select
Query this document for objects that match the given selector.
selector (JSON-like query dictionary) – you can query by type or by name, e.g. {"type": HoverTool}, {"name": "mycircle"}
{"type": HoverTool}
{"name": "mycircle"}
seq[Model]
select_one
Query this document 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
set_select
Update objects that match a given selector with the specified attribute/value updates.
selector (JSON-like query dictionary) – you can query by type or by name,i e.g. {"type": HoverTool}, {"name": "mycircle"} updates (dict) :
to_json
Convert this document to a JSON object.
JSON-data
to_json_string
Convert the document to a JSON string.
indent (int or None, optional) – number of spaces to indent, or None to suppress all newlines and indentation (default: None)
str
Turn off any active document hold and apply any collected events.
validate
Perform integrity checks on the modes in this document.
roots
A list of all the root models in this Document.
session_callbacks
A list of all the session callbacks on this document.
session_context
The SessionContext for this document.
SessionContext
session_destroyed_callbacks
A list of all the on_session_destroyed callbacks on this document.
template
A Jinja2 template to use for rendering this document.
template_variables
A dictionary of template variables to pass when rendering self.template.
self.template
theme
The current Theme instance affecting models in this Document.
Theme
Setting this to None sets the default theme. (i.e this property never returns None.)
Changing theme may trigger model change events on the models in the document if the theme modifies any model properties.
title
A title for this document.
This title will be set on standalone HTML documents, but not e.g. when autoload_server is used.
autoload_server
Navigate the tree on the left for information about each subcommand.