Encapsulate implicit state that is useful for Bokeh plotting APIs.
Generating output for Bokeh plots requires coordinating several things:
It is certainly possible to handle the configuration of these objects manually, and several examples of this can be found in examples/glyphs. When developing sophisticated applications, it may be necessary or desirable to work at this level. However, for general use this would quickly become burdensome. The bokeh.state module provides a State class that encapsulates these objects and ensures their proper configuration.
Manage state related to controlling Bokeh output.
a default document to use
dict
default filename, resources, etc. for file output This dictionary has the following form:
{
'filename' : # filename to use when saving
'resources' : # resources configuration
'autosave' : # whether to autosave
'title' : # a title for the HTML document
}
bool
whether to generate notebook output
a default session for Bokeh server output
Output to a static HTML file.
Parameters: |
|
---|
Warning
This output file will be overwritten on every save, e.g., each time show() or save() is invoked, or any time a Bokeh plotting API causes a save, if autosave is True.
Generate output in Jupyter/IPython notebook cells.
Parameters: |
|
---|---|
Returns: | None |
Store Bokeh plots and objects on a Bokeh server.
Parameters: |
|
---|---|
Returns: | None |
Warning
Calling this function will replace any existing default session.
Deactivate all currently active output modes.
Subsequent calls to show() will not render until a new output mode is activated.
Returns: | None |
---|
Functions for configuring Bokeh output.
Return the document for the current default state.
Returns: | the current default document object. |
---|---|
Return type: | doc |
Note
When using this API form within the server (e.g. in a Bokeh app), the appropriate document from the request context is returned, rather than the standard default global state. Doing so allows the same code using curdoc() to function correctly whether it is being run inside a server or not.
Return the session for the current default state, if there is one.
Returns: | the current default session object (or None) |
---|---|
Return type: | session |
Generate a plot that arranges several subplots into a grid.
Parameters: |
|
---|
Note
plot_arrangement can be nested, e.g [[p1, p2], [p3, p4]]
Returns: | a new GridPlot |
---|---|
Return type: | grid_plot |
Generate a layout that arranges several subplots horizontally.
Configure the default output state to generate output saved to a file when show() is called.
Parameters: |
|
---|---|
Returns: | None |
Note
Generally, this should be called at the beginning of an interactive session or the top of a script.
Warning
This output file will be overwritten on every save, e.g., each time show() or save() is invoked, or any time a Bokeh plotting API causes a save, if autosave is True.
Configure the default output state to generate output in Jupyter/IPython notebook cells when show() is called.
Parameters: |
|
---|---|
Returns: | None |
Note
Generally, this should be called at the beginning of an interactive session or the top of a script.
Configure the default output state to generate output that gets pushed to a bokeh-server when show() or push() is called.
Parameters: |
|
---|---|
Returns: | None |
Note
Generally, this should be called at the beginning of an interactive session or the top of a script.
Warning
Calling this function will replace any existing default session.
Update the server with the data for the current document.
Will fall back to the default output state (or an explicitly provided State object) for session or document if they are not provided.
Parameters: |
|
---|---|
Returns: | None |
Clear the default state of all output modes.
Returns: | None |
---|
Save an HTML file with the data for the current document.
Will fall back to the default output state (or an explicitly provided State object) for filename, resources, or title if they are not provided.
Parameters: |
|
---|---|
Returns: | None |
Raises: | RuntimeError – |
Immediately display a plot object.
In an IPython/Jupyter notebook, the output is displayed in an output cell. Otherwise, a browser window or tab is autoraised to display the plot object.
If both a server session and notebook output have been configured on the default output state then the notebook output will be generated to load the plot from that server session.
Parameters: |
|
---|---|
Returns: | None |
Note
The browser and new parameters are ignored when showing in an IPython/Jupyter notebook.
Generate a layout that arranges several subplots vertically.
The resources module provides the Resources class for easily configuring how BokehJS code and CSS resources should be located, loaded, and embedded in Bokeh documents.
Also provides some pre-configured Resources objects:
load minified BokehJS from CDN
provide minified BokehJS from library static directory
The Resources class encapsulates information relating to loading or embedding BokehJS code and CSS.
Parameters: |
|
---|
The following mode values are available for configuring a Resource object:
Once configured, a Resource object exposes the following public attributes:
location of the BokehJS logo image
any raw JS that needs to be placed inside <script> tags
any raw CSS that needs to be places inside <style> tags
URLs of any JS files that need to be loaded by <script> tags
URLS od any CSS files that need to be loaed by <link> tags
any informational messages concering this configuration
These attributes are often useful as template parameters when embedding Bokeh plots.
This module provides functions for embedding Bokeh plots in various different ways.
There are a number of different combinations of options when embedding Bokeh plots. The data for the plot can be contained in the document, or on a Bokeh server, or in a sidecar JavaScript file. Likewise, BokehJS may be inlined in the document, or loaded from CDN or a Bokeh server.
The functions in bokeh.embed provide functionality to embed in all these different cases.
Return a script tag that can be used to embed Bokeh Plots from a Bokeh Server.
The data for the plot is stored on the Bokeh Server.
Parameters: |
|
---|---|
Returns: | a <script> tag that will execute an autoload script loaded from the Bokeh Server |
Return type: | tag |
Return JavaScript code and a script tag that can be used to embed Bokeh Plots.
The data for the plot is stored directly in the returned JavaScript code.
Parameters: |
|
---|---|
Returns: | (js, tag) : JavaScript code to be saved at script_path and a <script> tag to load it |
Raises: | ValueError – |
Return HTML components to embed a Bokeh plot.
The data for the plot is stored directly in the returned HTML.
Note
The returned components assume that BokehJS resources are already loaded.
Parameters: |
|
---|---|
Returns: | (script, div) : UTF-8 encoded |
Return an HTML document that embeds a Bokeh plot.
The data for the plot is stored directly in the returned HTML.
Parameters: |
|
---|---|
Returns: | standalone HTML document with embedded plot |
Return type: | html |
Return HTML for a div that will display a Bokeh plot in an IPython Notebook
The data for the plot is stored directly in the returned HTML.
Parameters: | plot_object (PlotObject) – Bokeh object to render typically a Plot or PlotContext |
---|---|
Returns: | UTF-8 encoded HTML text |
Return type: | div |
Note
Assumes bokeh.load_notebook() or the equivalent has already been executed.
The templates module contains templates used by Bokeh to enable embedding Bokeh plots in various ways.
This template is for loading BokehJS code and css according to the configuration in a Resources object.
param css_files: | |
---|---|
a list of URIs for CSS files to include | |
type css_files: | list[str] |
param js_files: | a list of URIs for JS files to include |
type js_files: | list[str] |
param css_raw: | a list of raw CSS snippets to put between <style> tags |
type css_raw: | list[str] |
param js_raw: | a list of raw JS snippets to put between <style> tags |
type js_raw: | list[str] |
This template is for creating a basic plot div (to be used in conjunction with PLOT_JS).
param elementid: | |
---|---|
a unique identifier for the div a PLOT_JS template should be configured with the same elementid | |
type elementid: | str |
This template is for creating the JavaScript code snippet that can render a plot into a corresponding PLOT_DIV.
param modelid: | The Bokeh model id for the object to render typically for a Plot, PlotContext, etc. |
---|---|
type modelid: | str |
param modeltype: | |
the type of the model to render used to reference the appropriate Backbone collection | |
type modeltype: | str |
param elementid: | |
the id of the div to render the plot into | |
type elementid: | str |
This template is for creating a full <script> tag for raw JS code. Useful with the PLOT_JS template.
param plot_js: | raw JavaScript code to include |
---|---|
type plot_js: | str |
This template is for rendering Bokeh plots into a basic .html file.
param title: | a value for <title> tags |
---|---|
type title: | str |
param plot_resources: | |
typically the output of RESOURCES | |
type plot_resources: | |
str | |
param plot_script: | |
typically the output of PLOT_SCRIPT | |
type plot_script: | |
str | |
param plot_div: | typically the output of PLOT_DIV |
type plot_div: | str |
param Users can customize the file output by providing their own template with these parameters.: | |
This template is for loading BokehJS code and CSS into the IPython Notebook according to a resources configuration.
param plot_resources: | |
---|---|
typically the output of RESOURCES | |
type plot_resources: | |
str | |
param log_url: | URL to Bokeh logo to dispay |
type log_url: | str |
param verbose: | whether to display verbose info about BokehJS configuration, etc |
type verbose: | bool |
param bokeh_version: | |
the current version of Bokeh | |
type bokeh_version: | |
str | |
param js_info: | information about the location, version, etc. of BokehJS code |
type js_info: | str |
param css_info: | information about the location, version, etc. of BokehJS css |
type css_info: | str |
param warnings: | list of warnings to display to user |
type warnings: | list[str] |
This template is for rendering a Bokeh plot into the IPython Notebook.
param plot_script: | |
---|---|
typically the output of PLOT_SCRIPT | |
type plot_script: | |
str | |
param plot_div: | typically the output of PLOT_DIV |
type plot_div: | str |
This template is for creating a sidecar JS file that will automatically and asynchronously load BokehJS (if necessary) and then replaces the script tag that loads it (with appropriate attributes) with a rendered plot.
This template is for creating <script> tags that run AUTOLOAD scripts for plots that connect to a Bokeh Server for their data
param src_path: | path to AUTOLOAD script |
---|---|
type src_path: | str |
param elementid: | |
the a unique id for the script tag | |
type elementid: | str |
param modelid: | The Bokeh model id for the object to render typically for a Plot, PlotContext, etc. |
type modelid: | str |
param root_url: | root URL of the Bokeh Server |
type root_url: | str |
param docid: | document ID for the document on the server to load |
type docid: | str |
param docapikey: | |
API key for the document | |
type docapikey: | str |
This template is for creating <script> tags that run AUTOLOAD scripts for plots that have their data embedded in the AUTOLOAD script
param src_path: | path to AUTOLOAD script |
---|---|
type src_path: | str |
param elementid: | |
the a unique id for the script tag | |
type elementid: | str |
param modelid: | The Bokeh model id for the object to render typically for a Plot, PlotContext, etc. |
type modelid: | str |
param modeltype: | |
the type of the model to render used to reference the appropriate Backbone collection | |
type modeltype: | str |
Note
This script injects a <div> in place, so must be placed under <body>.