Bokeh doesn't load resources correctly when loading saved notebook
See original GitHub issueOpening this issue on request of Luke Canavan per a discussion on twitter about bokeh plotting with nteract
’s papermill
.
First off, I love the library and I thank y’all for the hard work.
ALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)
Python 3.6.1, confirmed issue on local macbook and on ec2 instances, as well as in ubuntu docker.
bokeh==1.0.0
geoviews==1.5.3
holoviews==1.10.7
Description of expected behavior and the observed behavior
Expected behaviour: plots render the same way when generated through a triggered notebook as when they are run by opening the notebook and clicking “run all cells”.
Actual behaviour: notebook registers and displays the holoviews (if using holoviews) and bokeh “extension insignia” but silently produces no plots when run via papermill
.
Complete, minimal, self-contained example code that reproduces the issue
Notebook to be run via papermill:
my_notebook.ipynb
import warnings
warnings.filterwarnings('ignore')
import geoviews as gv
import holoviews as hv # or import bokeh directly, same
hv.notebook_extension('bokeh') # NOTE: when set to `matplotlib` everything works
gv.extension('bokeh') # NOTE: when set to `matplotlib` everything works
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = 'all'
%matplotlib inline
from my_module import *
# NOTE: both of the below are passed in to the NB via `papermill` parameters cell
# NOTE: problem persists even if everything is hard-coded in and params are omitted
locals()[fn_name](**fn_params)
Please note that the issue persists when using simply bokeh or holoviews (bokeh backend) plots as well, this just happens to be what I was working on. The screen grab below shows matplotlib backend producing various plots, including simple ones, that are not output by bokeh:
# inside `my_module`
def a_fn_named_fn_name():
dallas_zips_raw = gpd.read_file("tx_texas_zip_codes_geo.min.json")
dallas_zips = dallas_zips_raw.astype({c: float for c in ("INTPTLON10", "INTPTLAT10")}).query(
"""(-97.54 < INTPTLON10 < -96.483) and (32.53 < INTPTLAT10 < 33.158)"""
)
# plot a geopandas df using geoviews (removing both from the equation does not mitigate issue)
dallas_zips_plot = gv.Polygons(gpd.GeoDataFrame(dallas_zips), vdims=[], label="DFW")
papermill.display("test0", "TEST0")
papermill.display("test", dallas_zips_plot)
Stack traceback and/or browser JavaScript console output
None, no warnings either, rather, a silent failure to produce plots.
Screenshots or screencasts of the bug in action
This is the screen grab from matplotlib
(for bokeh backend the holoviews and bokeh insignias appear but no plots):
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
trusting worked!!! tyvm all.
not at all your fault, but notebooks should at least make a good faith effort to surface to me, the end user, that there is additional content that was suppressed for security reasons: otherwise it appears as a silent failure!
I think the issue likely has the same root cause as described here: https://github.com/bokeh/jupyterlab_bokeh/issues/49#issuecomment-409651117
@mstewart141 (thanks for opening the issue BTW) If you have a second, do you mind trying the suggested workaround of loading Bokeh like:
In terms of writing a fix, is there a better way to handle the missing DOM element (https://github.com/bokeh/bokeh/blob/13baccbb2835f7d5831c22b5cf68214e89c02618/bokeh/core/_templates/autoload_js.js#L79) which happens when notebooks are executed asynchronously? Is it acceptable to just not add the
BokehJS is loaded
banner but still load in such a case?