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.

Plots not shown in HTML export for default Plotly renderer

See original GitHub issue

Environment data

  • VS Code version: 1.59.0
  • Jupyter Extension version (available under the Extensions sidebar): v2021.8.1195043623
  • Python Extension version (available under the Extensions sidebar): v2021.8.1105858891
  • OS (Windows | Mac | Linux distro) and version: Windows 10 20H2
  • Python and/or Anaconda version: 3.9.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): NA
  • Jupyter server running: Local

Expected behaviour

Plots are visible when exporting to HTML

Actual behaviour

Plots are not shown (and there is no track of it in the HTML source code)

Steps to reproduce:

import plotly.express as px
fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
fig.show()

The temporary notebook for exporting (%localappdata%\temp<UUID>\export.ipynb) already misses the expected output.

Switching the Plotly renderer to notebook using fig.show(renderer='notebook') provides the expected plot output in the exported HTML

On a side note, the iframe / iframe_connected renderer types don’t produce any plot output in VS Code but the export to HTML works as expected. It seems that iframes are not working/are not supported in VS Code right now (it has worked a while back) - maybe worth another bug entry.

Export to PDF probably has the same issue - not checked.

Logs

Output for Jupyter in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)

XXX

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

11reactions
congyiwucommented, Sep 22, 2021

~The best~ (EDIT: another) workaround I’ve found is to enable multiple renders in Plotly. With the snippet below, I see a single interactive plot in both the VS Code UI and exported HTML.

  • The Plotly docs suggest that enabling multiple renderers is the intended solution, although it would be nice if it just magically worked by default.
  • The main downside (if you commit ipynb files to Git) is probably that this bloats the ipynb file, but I’m using the Jupytext for Notebooks VS Code extension to automatically strip outputs.
    • Actually I’m using a fork ofteh extension with some tweaks I’m trying to upstream.
import plotly.express as px
import plotly.io as pio

# This ensures Plotly output works in multiple places:
# plotly_mimetype: VS Code notebook UI
# notebook: "Jupyter: Export to HTML" command in VS Code
# See https://plotly.com/python/renderers/#multiple-renderers
pio.renderers.default = "plotly_mimetype+notebook"

fig = px.line(...)
fig.show()
1reaction
mikayla-eckelcifresecommented, Jun 24, 2022

~The best~ (EDIT: another) workaround I’ve found is to enable multiple renders in Plotly. With the snippet below, I see a single interactive plot in both the VS Code UI and exported HTML.

  • The Plotly docs suggest that enabling multiple renderers is the intended solution, although it would be nice if it just magically worked by default.

  • The main downside (if you commit ipynb files to Git) is probably that this bloats the ipynb file, but I’m using the Jupytext for Notebooks VS Code extension to automatically strip outputs.

    • Actually I’m using a fork ofteh extension with some tweaks I’m trying to upstream.
import plotly.express as px
import plotly.io as pio

# This ensures Plotly output works in multiple places:
# plotly_mimetype: VS Code notebook UI
# notebook: "Jupyter: Export to HTML" command in VS Code
# See https://plotly.com/python/renderers/#multiple-renderers
pio.renderers.default = "plotly_mimetype+notebook"

fig = px.line(...)
fig.show()

Thank you SO MUCH for this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exporting Jupyter notebook with plotly to html not displaying ...
I am using Jupyter lab, everything works fine within jupyter lab even when I am offline. However whenever I try to export the...
Read more >
Displaying figures in Python - Plotly
To display a figure using the renderers framework, you call the .show() method on a graph object figure, or pass the figure to...
Read more >
Interactive html export in Python - Plotly
Plotly allows you to save interactive HTML versions of your figures to your local disk. New to Plotly? Plotly is a free and...
Read more >
Plotly not loading in browser - Plotly Python
Do you have the same issues displaying figures if you try to run a Jupyter Notebook ... Maybe your default renderer is not...
Read more >
HTML export from Jupyter Notebook for offline viewing
When I export HTML from Jupyter Notebook, the plot.ly figures only show if ... Uncaught ReferenceError: require is not defined Is this intended…...
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