HTML export from Jupyter Notebook for offline viewing

When I export HTML from Jupyter Notebook, the figures only show if there is an internet connection. Otherwise, I get the following error message:

Uncaught ReferenceError: require is not defined

Is this intended behavior? I would have imagined that a static HTML file is supposed to be able to function on its own.

1 Like

Hi @realtime, which version of plotly are you using? And how do you export to HTML? (with fig.write_html('tmp.html')?) Could you please share a reproducible code example using dummy data so that we can try to reproduce or diagnose the problem?

I use version 4.3.0
I create the export via the Jupyter Notebook menu: File - Download as - HTML
The following trivial code reproduces the issue for me:

import as px
iris =
px.scatter(iris, x="sepal_width", y="sepal_length", color="petal_length")

Thanks for your support.

Are you using Jupyter notebook or Jupyter lab? Your problem seems quite close to which was fixed following the instructions in

It’s Notebook. For me, Lab is too fragile for daily use. :wink:

1 Like

OK. It could also be related to a template issue as decribed in Could you maybe do more diagnosis using nbconvert instead of the jupyter menu as descrived in the former issue? Do you confirm that you want to download the whole notebook and not only the figure? Because you can also save a figure with fig.write_html.

jupyter nbconvert --to html ...

shows exactly the same behavior, the output files are identical. And, yes, I want the full notebook.

I also tried fig.write_html(...) as you suggested, and this indeed works flawlessly. But it is not what I want.

With the nbconvert command, did you try the different templates as in (--template full)?

--full gives the identical HTML output as before, and with --basic the figure does not work at all, even online. I don’t mind the latter since the overall file renders quite ugly anyway and thus I strongly prefer --full. :wink:

I am still not sure where we are here:

Is this a bug or a missing feature? So do I file a bug report or a feature request?

Oh it’s definitely a bug, I just don’t know whether it’s more a plotly or a jupyter/nbconvert bug. Anyway since we’re at the end of the chain you might as well open an issue on Thanks!

I opened the issue report

Oh I had completely missed the fact that the problem only happens when there is no Internet connection. Did you try to change the renderer to notebook (see

import as pio
pio.renderers.default = "notebook"

pio.renderers.default = "notebook" does not change anything. Same issue, same error message.

Shouldn’t this be the default renderer for Jupyter Notebook anyway since it is the most universal? The description in the documentation is quite fuzzy: attempts to autodetect an appropriate renderer at startup.