Jupyter Bokeh
Jupyter Bokeh is a Jupyter extension that enables Bokeh plots to render interactively within Jupyter notebooks and JupyterLab environments. It acts as a bridge, ensuring that Bokeh's rich interactive visualizations work seamlessly. The current version is 4.0.5, and it follows Bokeh's release cadence, typically updating to support new Bokeh features and Jupyter environments.
Common errors
-
JavaScript output is disabled in JupyterLab
cause The JupyterLab output area is configured to not execute JavaScript, often for security reasons or by default for specific output types.fixRight-click on the output cell in JupyterLab and select 'Enable Javascript/HTML Output' or check your JupyterLab settings for default output behavior. -
Error loading script: http://localhost:8888/nbextensions/jupyter_bokeh/index.js
cause The `jupyter-bokeh` Jupyter Notebook extension was not properly enabled or is not accessible.fixRun `jupyter nbextension enable --py --sys-prefix jupyter_bokeh` and restart your Jupyter Notebook server. -
ModuleNotFoundError: No module named 'bokeh'
cause `bokeh` is not installed in the current Python environment.fixInstall Bokeh: `pip install bokeh`. -
Bokeh: ERROR: Unable to display Bokeh plots in the Jupyter notebook. When showing a plot, make sure the corresponding notebook extension is loaded. Refer to the 'set up' section on the Bokeh user guide for more information.
cause `jupyter-bokeh` is installed but the corresponding Jupyter extension is not enabled, or the `bokeh` notebook extension is not properly configured.fixEnsure `jupyter-bokeh` is installed and enabled: `pip install jupyter-bokeh` then `jupyter nbextension enable --py --sys-prefix jupyter_bokeh` (for Notebook) or `jupyter labextension install @jupyter-widgets/jupyterlab-manager` (for Lab). Restart Jupyter after enabling.
Warnings
- gotcha Jupyter extension not properly enabled after installation may prevent plots from rendering or interacting correctly.
- breaking Incompatible `bokeh` or `ipywidgets` versions can lead to rendering issues or broken interactivity.
- gotcha Plots might appear as static images or not at all if the JavaScript frontend assets fail to load or are blocked.
- gotcha Plots not updating or interacting correctly when using complex Bokeh layouts or callbacks in Jupyter.
Install
-
pip install jupyter-bokeh -
jupyter nbextension enable --py --sys-prefix jupyter_bokeh jupyter labextension install @jupyter-widgets/jupyterlab-manager
Imports
- JupyterBokeh
from jupyter_bokeh.widget import JupyterBokeh
Quickstart
from bokeh.plotting import figure, show # Create a new plot with a title and axis labels p = figure(title="My First Bokeh Plot", x_axis_label='x', y_axis_label='y') # Add a circle renderer with size, color, and alpha p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=10, color="navy", alpha=0.5) # Show the results in the notebook show(p)