bokeh.core.state

Encapsulate implicit state that is useful for Bokeh plotting APIs.

Note

While State objects can also be manipulated explicitly, they are automatically configured when the functions output_file(), etc. from bokeh.io are used, so this is not necessary under typical usage.

Generating output for Bokeh plots requires coordinating several things:

Document
Groups together Bokeh models that may be shared between plots (e.g., range or data source objects) into one common strucure.
Resources
Control how JavaScript and CSS for the client library BokehJS are included and used in the generated output.

It is possible to handle the configuration of these things manually, and some examples of doing this can be found in examples/models directory. When developing sophisticated applications, it may be necessary or desirable to work at this level. However, for general use this would quickly become burdensome. This module provides a State class that encapsulates these objects and ensures their proper configuration in many common usage scenarios.

class State[source]

Manage state related to controlling Bokeh output.

output_file(filename, title='Bokeh Plot', mode='cdn', root_dir=None)[source]

Configure output to a standalone HTML file.

Calling output_file not clear the effects of any other calls to output_notebook, etc. It adds an additional output destination (publishing to HTML files). Any other active output modes continue to be active.

Parameters:
  • filename (str) – a filename for saving the HTML document
  • title (str, optional) – a title for the HTML document
  • mode (str, optional) –

    how to include BokehJS (default: 'cdn')

    One of: 'inline', 'cdn', 'relative(-dev)' or 'absolute(-dev)'. See Resources for more details.

  • root_dir (str, optional) –

    root dir to use for absolute resources (default: None)

    This value is ignored for other resource types, e.g. INLINE or``CDN``.

Warning

The specified output file will be overwritten on every save, e.g., every time show() or save() is called.

output_notebook()[source]

Generate output in Jupyter notebook cells.

Calling output_notebook not clear the effects of any other calls to output_file, etc. It adds an additional output destination (publishing to notebook output cells). Any other active output modes continue to be active.

Returns:None
output_server(session_id='default', url='default', app_path='/')[source]

Store Bokeh plots and documents on a Bokeh server.

Warning

The use of the higher level function bokeh.io.output_server has be deprecated. This support function will also be removed when that deprecation is complete.

Parameters:
  • session_id (str) –

    Name of session to push on Bokeh server

    *Any existing session with the same id will be overwritten.*

  • url (str, optional) – base URL of the Bokeh server (default: “default”) If “default” use the default localhost URL.
  • app_path (str, optional) – relative path of the app on the Bokeh server (default: “/”)
Returns:

None

reset()[source]

Deactivate all currently active output modes and set curdoc() to a fresh empty Document.

Subsequent calls to show() will not render until a new output mode is activated.

Returns:None
app_path

A relative app path for a Bokeh server app.

Warning

This property is deprecated.

document

A default Document to use for all output operations.

file

A dict with the default configuration for file output (READ ONLY)

The dictionary value has the following form:

{
    'filename'  : # filename to use when saving
    'resources' : # resources configuration
    'title'     : # a title for the HTML document
}
notebook

Whether to generate notebook output on show operations. (READ ONLY)

server_enabled

Whether to generate output on a Bokeh server. (READ ONLY)

Warning

This property is deprecated.

server_url

A full URL (including the app path) for a Bokeh server app.

Warning

This property is deprecated.

session_id

A default session ID for Bokeh server output. (READ ONLY)

Warning

This property is deprecated.

session_id_allowing_none

A session ID for Bokeh server output, or None. (READ ONLY)

Warning

This property is deprecated.

url

A base URL (not including any app path) for a Bokeh server.

Warning

This property is deprecated.