-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plots not shown in HTML export for default Plotly renderer #6999
Comments
@jackthepanisher Is this export to HTML from the interactive window or from a notebook? |
@joyceerhl the behavior is the same for notebook and interactive window. I can also mix multiple Note: |
Thanks for the answer, I can reproduce the problem. |
I am seeing that the plots are persisted to disk in the ipynb file, so they're getting omitted from the generated html during the nbconvert process. |
Opening the notebook on the Jupyter server directly ( |
Well, I tried to load the notebook also with JupyterLab. There the vscode aka plotly_mimetype does show up but the notebook one does not. So maybe that is expected for classical notebook server vs. JupyterLab. However, when exporting the notebook from JupyterLab to HTML, the vscode/plotly_mimetype one shows up as static image and the notebook one also shows up as an interactive graph. I guess the expectation for VS Code is to have an output produced in some way for the default renderer, even if it is a static image. If producing an interactive graph for the HTML export is a limitation of the mime type renderer in general, I would really like to switch to the notebook renderer instead, as I've experienced better results and behavior with it. Currently, issue #6404 is some remaining piece for me to switch to the notebook renderer entirely. |
Running nbconvert directly using
It looks like nbconvert doesn't like the Plotly mime type + json format that is generated with |
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() |
Hmm, it turns out I see output in both places w/ just the "notebook renderer":
|
@congyiwu thanks for providing another workaround using multiple renderers. I already mentioned using just the notebook renderer in the first post but this has some other drawbacks like re-opening will currently not show plots rendered with the notebook renderer (see issue #6404). So using multiple renderers might be a better workaround until this is fixed. |
I get the same problem. My ipynb output a object type <IPython.core.display.HTML object>. Then It don't render in view. And Test Normal on jupyter-notebook server. |
This isn't an issue with import/export, i.e. there's nothing wrong with our import export code. To me this is an nb-golden, the notebook cannot be saved as HTML, we might want to find the exact cause and notify plotly/nbconvert about this. Possible they area aware of this, but we don't seem to know what's going on and i think we should update this issue accordingly. |
Per @DonJayamanne, this issue is not one we can resolve within the Jupyter extension. |
talked to @greazer. Another customer ran into this. Is this something we can do in the Jupyter extension to make it just work out of box? |
Note:
I think the changes in the default mime type to Based on previous comments it seems this wasn't the default mime type in Plotly package, see here #6999 (comment), #6999 (comment) Users with the new plotly versions might not have issues (at least I don't) , and users with older versions might have issues (which could be whats going on here). We could optionally update the startup commands to change the defaults. Suggestion:
|
If Plotly runs in VS Code env, the renderer will default to If VS Code\Jupyter wants to go the route of Another note is that |
Thank you SO MUCH for this! |
Closing this as an upstream issue, unfortunately there's nothing mujch we can do here, the generated mime types from the plotly package needs to contain text/html as well. Issue is here plotly/plotly.py#3977 |
@DonJayamanne, although there are some workarounds available VS Code could be a bit more verbose when handling such case. Currently, there is no indication to the user that the HTML export is failing to produce the graphs with the default settings. Without any specific renderer specified, VS Code uses the default Plotly renderer set to The difference to JupyterLab is that even with the renderer set to Furthermore, converting a notebook with nbconvert using
It would be good if VS Code could produce a similar warning, if possbile, when trying to export For completeness, another method for exporting is to use nbconvert and set the PLOTLY_RENDERER environment variable to a supported renderer method like
|
I don't think we need special cases for plotly, if there is no HTML output i don't think we should make any assumptions and warn or display messages to a user or in the logs. Because if the user ran nbconvert they'd get the exact same results.
this is not true. VS Code doesn't change how plotly generates outputs. Its the plotly package that produces the different mime types, not vscode. Hence the reason for filing an issue upstream.
Agreed, will file an issue for this.
However this ends up running the whole notebook all over again. I don't thiknk this is a good thing. What if notebook,s end up having code that modify state on disc or the like. Also exports could take a long time. |
Agreed. Having the error/warning bubble up from nbconvert should be sufficient.
Correct. Sorry for the confusion. It's Plotly's setting that is set according to the detected environment. I also don't like the 'vscode+notebook' workaround as it produces bigger notebook files only to be able to export to HTML which is probably not used that frequently.
Yes, this was more meant to be a manual workaround not to be part of any VS Code workflow. |
Oh, wow, thanks @jackthepanisher! I was breaking my head for many hours to figure out how I could export an interactive time series plot to HTML. I finally got it working with that renderer. I also could not figure it out with matplotlib widgets, which resulted in static images inside the HTML page. |
Environment data
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:
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 HTMLOn 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 theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toJupyter
)The text was updated successfully, but these errors were encountered: