question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bokeh doesn't load resources correctly when loading saved notebook

See original GitHub issue

Opening 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): image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mstewart141commented, Nov 13, 2018

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!

1reaction
canavandlcommented, Nov 6, 2018

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:

from bokeh.plotting import output_notebook, figure, show

output_notebook(hide_banner=True)

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bokeh plot not showing in Jupyter. Only says "Loading ...
Bokeh plots rely on a JavaScript library, BokehJS. By default (and by popular demand) BokehJS is loaded remotely from a CDN (specifically, ...
Read more >
Resources and Embedding — Bokeh 0.8.2 documentation
The resources module provides the Resources class for easily configuring how BokehJS code and CSS resources should be located, loaded, and embedded in...
Read more >
Introduction to plotting with Bokeh - BE/Bi 103 a
... import bokeh.io import bokeh.plotting # Enable viewing Bokeh plots in the notebook bokeh.io.output_notebook(). BokehJS 2.4.3 successfully loaded.
Read more >
Visualizing Data with Bokeh and Pandas
This is important because often data loaded from a csv file will not be properly typed as datetime. Supplying the format argument is...
Read more >
Interactive Data Visualization in Python With Bokeh
This Python tutorial will get you up and running with Bokeh, ... you may have noticed that the default Bokeh figure comes pre-loaded...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found