vscode-jupyter: Plots not shown in HTML export for default Plotly renderer
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 (View
→Output
, change the drop-down the upper-right of the Output
panel to Jupyter
)
XXX
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 8
- Comments: 22 (8 by maintainers)
~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.
Thank you SO MUCH for this!
Running nbconvert directly using
py -m jupyter nbconvert notebook.ipynb --to html --output notebook.html
reveals:It looks like nbconvert doesn’t like the Plotly mime type + json format that is generated with
renderer='vscode'
. There are some tracks of it in https://github.com/jupyter/nbconvert/issues/944. JupyterLab appears to use a Plotly extension to convert the mime type to static images. Not sure if VS Code should support something similar. Right now the notebook renderer(s) seem to provide the only option to export Plotly graphs to HTML from within VS Code.@joyceerhl the behavior is the same for notebook and interactive window. I can also mix multiple
fig.show(renderer='vscode')
andfig.show(renderer='notebook')
statements where plots are shown for both cases in the notebook/interactive window but only therenderer='notebook'
one shows up in the HTML export.Note:
fig.show(renderer='vscode')
is the default setting in VS Code i.e. same asfig.show()