Plot Objects

bokeh

The bokeh module itself contains a few useful functions for testing and reporting issues:

test(verbosity=1, xunitfile=None, exit=False)

Run the full Bokeh test suite, and output the results of the tests to sys.stdout.

This function uses nosetests to discover which tests to run, and will run tests in any ‘tests’ subdirectory within the Bokeh module.

Parameters:
  • verbosity (int, optional) – Acceptable values are 0 (less verbose) to 2 (most verbose)
  • xunitfile (str, optional) – Write xunit-style XML test results to a given filename. This is useful for running tests on a CI server. (default: None)
  • exit (bool, optional) – Whether to return or exit. If True, call sys.exit with an error code after the tests are finished. (default: False)
Returns:

Nose return code

Return type:

int

bokeh.document

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

class Document(json_objs=None)

The Document class is a container to hold Bokeh objects that requires reflecting to the client BokehJS library.

autoadd

bool

autostore

bool

context

PlotContext

the plot context for this document

ref

str

reference to the plot context for this document

add(*objects)

Add top-level objects (and any references they hold to sub-objects) to this Document.

Warning

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

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

Remove all plots from this Document

Returns:None
clear_callback_queue(models=None)

Clear the callback queue on given models.

Parameters:models (seq[PlotObject], optional) – models to clear callbacks for (default: None) If models is None, clears callback queue on all models in this Document.
Returns:None
disable_callbacks(models=None)

Disable callbacks on given models.

Parameters:models (seq[PlotObject], optional) – models to disable callbacks for (default: None) If models is None, disables callbacks on all models in this Document.
Returns:None
dump(*models)

Convert models to json objects.

Parameters:*models (PlotObject) – models to convert to json objects If models is empty, dump converts all models in this d ocument.
Returns:json objects
Return type:dict
enable_callbacks(models=None)

Enable callbacks on given models.

Parameters:models (seq[PlotObject], optional) – models to enable callbacks for (default: None) If models is None, enables callbacks on all models in this Document.
Returns:None
execute_callback_queue(models=None)

Execute all queued callbacks on the given models.

Parameters:models (seq[PlotObject], optional) – models to execute callbacks for (default: None) If models is None, executes the callback queue on all models in this Document.
Returns:None
load(*objs, **kwargs)

Convert json objects to models and load them into this Document.

Parameters:

*objs (str) – json object strings to convert

Keyword Arguments:
 
  • Two optional keyword arguments are stripped from *kwargs:
  • existing (str) – what objects to trigger events on (default: ‘existing’) valid values are: * ‘none’ trigger no events * ‘all’ trigger events on all models * ‘new’ trigger events only on new models * ‘existing’ trigger events on already existing models
  • dirty (bool) – whether to mark models as dirty (default: False)
Returns:

set[Plotobject] : models loaded from json

merge(json_objs)

Merge’s json objects from another document into this one using the plot context id from the json_objs which are passed in children from this document are merged with the children from the json that is passed in

Parameters:json_objs – json objects from session.pull()
Returns:None
prune()

Remove all models that are not in the plot context

bokeh.session

The session module provides the Session class, which encapsulates a connection to a Document that resides on a Bokeh server.

The Session class provides methods for creating, loading and storing documents and objects, as well as methods for user-authentication. These are useful when the server is run in multi-user mode.

class Session(name='http://localhost:5006/', root_url='http://localhost:5006/', userapikey='nokey', username='defaultuser', load_from_config=True, configdir=None)

Encapsulate a connection to a document stored on a Bokeh Server.

Parameters:
  • name (str, optional) – name of server
  • root_url (str, optional) – root url of server
  • userapikey (str, optional) – (default: “nokey”)
  • username (str, optional) – (default: “defaultuser”)
  • load_from_config (bool, optional) – Whether to load login information from config. (default: True) If False, then we may overwrite the user’s config.
  • configdir (str) – location of user configuration information
base_url

str

configdir

str

configfile

str

http_session

requests.session

userapikey

str

userinfo

dict

username

str

browser_login()

Open a browser with a token that logs the user into a bokeh server.

Note

This is useful in multi-user mode.

Returns:None
data_source(name, data)

Makes and uploads a server data source to the server.

Note

The server must be configured with a data directory.

Parameters:
  • name (str) – name for the data source object
  • data (pd.DataFrame or np.array) – data to upload
Returns:

ServerDataSource

Return type:

source

execute(method, url, headers=None, **kwargs)

Execute an HTTP request using the current session.

Returns the response

Parameters:
  • method (string) – ‘get’ or ‘post’
  • url (string) – url
  • headers (dict, optional) – any extra HTTP headers
Keyword Arguments:
 

Any extra arguments to pass into the requests library

Returns:

response

Returns the response

execute_json(method, url, headers=None, **kwargs)

same as execute, except ensure that json content-type is set in headers and interprets and returns the json response

find_doc(name)

Return the docid of the document with a title matching name.

Note

Creates a new document with the given title if one is not found.

Parameters:name (string) – name for the document
Returns:str
Return type:docid
get_api_key(docid)

Retrieve the document API key from the server.

Parameters:docid (string) – docid of the document to retrive API key for
Returns:string
Return type:apikey
get_json(url, headers=None, **kwargs)

Return the result of an HTTP ‘get’.

Parameters:
  • url (str) – the URL for the ‘get’ request
  • headers (dict, optional) – any extra HTTP headers
Keyword Arguments:
 

Any extra arguments to pass into the requests library

Returns:

JSON

Return type:

response

list_data()

Return all the data soruces on the server.

Returns:JSON
Return type:sources
load()

Loads the server configuration information from disk

Returns:None
load_document(doc)

Loads data for the session and merge with the given document.

Parameters:doc (Document) – document to load data into
Returns:None
load_object(obj, doc)

Update an object in a document with data pulled from the server.

Parameters:
  • obj (PlotObject) – object to be updated
  • doc (Document) – the object’s document
Returns:

None

login(username, password)

Log a user into a bokeh server.

Note

This is useful in multi-user mode.

Parameters:
  • username (str) – user name to log in
  • password (str) – user password
Returns:

None

make_doc(title)

Makes a new document with the given title on the server

Note

user information is reloaded

Returns:None

Return a URL to a server page that will render the given object.

Parameters:obj (PlotObject) – object to render
Returns:str
Return type:url
poll_document(document, interval=0.5)

Periodically ask the server for updates to the document.

post_json(url, headers=None, **kwargs)

Return the result of an HTTP ‘post’

Parameters:
  • url (str) – the URL for the ‘get’ request
  • headers (dict, optional) – any extra HTTP headers
Keyword Arguments:
 

Any extra arguments to pass into the requests library

Returns:

JSON

Return type:

response

pull(typename=None, objid=None)

Pull JSON objects from the server.

Returns a specific object if both typename and objid are supplied. Otherwise, returns all objects for the currently configured document.

This is a low-level function.

Parameters:
  • typename (str, optional) – name of the type of object to pull
  • objid (str, optional) – ID of the object to pull

Note

you must supply either typename AND objid or omit both.

Returns:JSON
Return type:attrs
push(*jsonobjs)

Push JSON objects to the server.

This is a low-level function.

Parameters:*jsonobjs (JSON) – objects to push to the server
Returns:None
register(username, password)

Register a new user with a bokeh server.

Note

This is useful in multi-user mode.

Parameters:
  • username (str) – user name to register
  • password (str) – user password for account
Returns:

None

save()

Save the server configuration information to JSON

Returns:None
show(obj)

Display an object as HTML in IPython using its display protocol.

Parameters:obj (PlotObject) – object to display
Returns:None
store_document(doc, dirty_only=True)

Store a document on the server.

Returns the models that were actually pushed.

Parameters:
  • doc (Document) – the document to store
  • dirty_only (bool, optional) – whether to store only dirty objects. (default: True)
Returns:

list[PlotObject]

Return type:

models

store_objects(*objs, **kwargs)

Store objects on the server

Returns the objects that were actually stored.

Parameters:*objs (PlotObject) – objects to store
Keywords Args:
dirty_only (bool, optional) : whether to store only dirty objects. (default: True)
Returns:set[PlotObject]
Return type:models
use_doc(name=None, docid=None)

Configure the session to use a given document.

Parameters:
  • name (str, optional) – name of the document to use
  • docid (str, optional) – id of the document to use

Note

only one of name or docid may be supplied.

Creates a document for with the given name if one is not present on the server.

Returns:None
configdir

filename where our config are stored.

class TestSession(*args, **kwargs)

Currently, register and login do not work, everything else should work in theory, but we’ll have to test this as we go along and convert tests