API Reference¶
MyST-NB-Bokeh enables gluing and pasting Bokeh plots when using the MyST-NB Sphinx extension.
- class myst_nb_bokeh.BokehGlueDomain(env)¶
Bases:
sphinx.domains.DomainA Sphinx domain for handling Bokeh data.
- Parameters
env (BuildEnvironment) –
- Return type
- data_version = 1¶
Data version, bump this when the format of
self.datachanges
- has_bokeh(docname=None)¶
Return whether or not this page requires BokehJS.
- initial_data: dict[str, dict[str, bool]] = {'has_bokeh': {}}¶
Data value for a fresh environment.
has_bokehis a mapping of docnames to a Boolean whether or not it has Bokeh
- label = 'BokehGlue'¶
The label used for this domain
- name = 'bokeh_glue'¶
The name of this domain
- process_doc(env, docname, document)¶
Set internal data for whether or not this page requires BokehJS.
- class myst_nb_bokeh.BokehOutputRenderer(*args, **kwargs)¶
Bases:
myst_nb.render_outputs.CellOutputRendererRender Bokeh JSON output from a cell’s output.
This class extends the
CellOutputRendererclass to add a method that renders Bokeh JSON output into a<div>element in the page. We do this by adding a new key to the_render_mapattribute ofCellOutputRenderer. The key is the value of theJB_BOKEH_MIMETYPEmodule data member.- __init__(*args, **kwargs)¶
Initialize the
BokehOutputRenderer.Any positional or keyword arguments are passed to the superclass constructor. This class takes no additional arguments.
- render_bokeh(output, index)¶
Output Sphinx nodes for Bokeh plots given the JSON of the plot.
- Parameters
output (NotebookNode) – The output nodes from the cell.
NotebookNodeinstances can be accessed like dictionaries.index (int) – The cell index.
- Returns
A
listofdocutils.nodes.Nodeinstances. The two nodes returned here are the<div>that will contain the plot and a<script>with the appropriate BokehJS call to turn the JSON into a plot.- Return type
list[nodes.Node]
- myst_nb_bokeh.JB_BOKEH_MIMETYPE: str = 'application/jupyter-book-bokeh-json'¶
The mimetype that we use for JSON output from Bokeh. This is a custom mimetype to avoid conflicting with any actual mimetypes.
- myst_nb_bokeh.add_our_configuration(app, config)¶
Add the configuration for MyST-NB to the Sphinx configuration.
Designed to be connected to the
'config-inited'Sphinx event to ensure that all configuration sources have been read. The function signature is determined by the Sphinx API.- Parameters
app (Sphinx) – The Sphinx application instance.
config (Config) – The Sphinx configuration instance.
- Return type
- myst_nb_bokeh.glue_bokeh(name, variable, display=False)¶
Glue Bokeh figures into the cell output.
- Parameters
name (str) – The name to give to the
variablein the cell output. This name must be used when pasting this output in other cells.variable (object) – The object to be inserted into the cell output. Note that the object itself is not stored. Rather, this function inserts the JSON representation of the plot into the cell output, which must then be extracted and shown by the
BokehOutputRenderer.display (bool) – If
True, the plot will be shown in the output of the cell. Useful for sanity checking the output.Falseby default.
- Return type
- myst_nb_bokeh.install_bokeh(app, pagename, templatename, context, doctree)¶
Add BokehJS files to the page, if the page has Bokeh plots.
Designed to be connected to the
'html-page-context'Sphinx event. If the builder format is not an HTML file, this function does nothing. The function signature is determined by the Sphinx API.
- myst_nb_bokeh.setup(app)¶
Set up the MyST-NB-Bokeh Sphinx extension.
This function is automatically called by Sphinx, as long as this extension is listed in the list of extensions in your Sphinx
conf.pyfile.