bokeh.document

The document module provides the Document class, which is a container for all Bokeh objects that must be reflected to the client side BokehJS library.

class Document(**kwargs)
add(*args, **kwargs)

Call add_root() on each object.

Warning

This function should only be called on top level objects such as Plot, and Layout containers.

Parameters:*objects (Model) – objects to add to the Document
Returns:None

Deprecated in Bokeh 0.11.0; please use document.add_root instead.

add_next_tick_callback(callback)

Add callback to be invoked once on the next “tick” of the event loop.

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(callback, period_milliseconds)

Add a callback to be invoked on a session periodically.

Parameters:
  • callback (callable) – the callback function to execute
  • period_milliseconds (int) – the number of milliseconds that should be between each callback execution.

Note

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(model)

Add a model as a root model to this Document.

Any changes to this model (including to other models referred to by it) will trigger “on_change” callbacks registered on this Document.

add_timeout_callback(callback, timeout_milliseconds)

Add callback to be invoked once, after a specified timeout passes.

Note

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(patch)

Apply a JSON patch object created by parsing the result of create_json_patch_string()

apply_json_patch_string(patch)

Apply a JSON patch string created by create_json_patch_string()

clear()

Remove all content from the document (including roots, vars, stores) but do not reset title

create_json_patch_string(events)

Create a JSON string describing a patch to be applied with apply_json_patch_string()

Parameters:events – list of events to be translated into patches
Returns:JSON string which can be applied to make the given updates to obj
Return type:str
classmethod from_json(json)

Load a document from JSON.

classmethod from_json_string(json)

Load a document from JSON.

get_model_by_id(model_id)

Get the model object for the given ID or None if not found

get_model_by_name(name)

Get the model object for the given name or None if not found

on_change(*callbacks)

Invoke callback if the document or any Model reachable from its roots changes.

remove_next_tick_callback(callback)

Remove a callback added earlier with add_next_tick_callback()

Throws an error if the callback wasn’t added

remove_on_change(*callbacks)

Remove a callback added earlier with on_change()

Throws an error if the callback wasn’t added

remove_periodic_callback(callback)

Remove a callback added earlier with add_periodic_callback()

Throws an error if the callback wasn’t added

remove_root(model)

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_timeout_callback(callback)

Remove a callback added earlier with add_timeout_callback()

Throws an error if the callback wasn’t added

replace_with_json(json)

Overwrite everything in this document with the JSON-encoded document

select(selector)

Query this document for objects that match the given selector.

Parameters:selector (JSON-like query dictionary) – you can query by type or by name, e.g. {"type": HoverTool}, {"name": "mycircle"}
Returns:seq[Model]
select_one(selector)

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

Parameters:selector (JSON-like query dictionary) – you can query by type or by name, e.g. {"type": HoverTool}, {"name": "mycircle"}
Returns:Model
set_select(selector, updates)

Update objects that match a given selector with the specified attribute/value updates.

Parameters:selector (JSON-like query dictionary) – you can query by type or by name,i e.g. {"type": HoverTool}, {"name": "mycircle"} updates (dict) :
Returns:None
to_json()

Convert the document to a JSON object.

to_json_string(indent=None)

Convert the document to a JSON string.

Parameters:indent (int or None, optional) – number of spaces to indent, or None to suppress all newlines and indentation (default: None)
Returns:str
theme

Get the current Theme instance affecting models in this Document. Never returns None.

class UnlockedDocumentProxy(doc)

Wrap a Document object so that only methods that can safely be used from unlocked callbacks or threads are exposed. Attempts to otherwise access or change the Document results in an exception.

without_document_lock(f)

Mark a callback function to execute without first obtaining the document lock.

Warning

The value of curdoc() inside the callback will be None. Any attempt to modify the document inside the callback can result in data or protocol corruption.