-
Notifications
You must be signed in to change notification settings - Fork 566
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
Plotly plot not converted to HTML #944
Comments
It's because whereas calling We want to discourage the injection of scripts in notebook outputs in JupyterLab so we encourage people to use renderer extensions like plotly-extension. To solve this problem of making rich outputs show up in nbviewer and static nbconvert targets, plotly-extension and others inject a static image into the output: Unfortunately, You can either request that plotly.py offer some sort of fallback output for nbviewer, etc. or render you plotly charts using plotly-extension which ends up looking like your classic notebook code minus the import plotly.offline as py
import plotly.graph_objs as go
mesh = go.Mesh3d(x=[0,1,0],y=[0,0,1],z=[0,0,0],i=[0],j=[1],k=[2],flatshading=False,color='#333333')
py.iplot([mesh]) |
Right, thanks for the swift reply. Based on your comments, I have introduced a global variable that selects a mode which is either output or interactive. In output mode, the iplot function is used and in interactive mode, it uses the Widgets. I can see that not having scripts and html injected in the notebook might be a concern, but fallback output is terrible for anyone relying on the HTML as the target format of the notebook. For presentations or students hand-ins it is extremely convenient to be able to bake a notebook where the figures work, but no computation takes place. Consequently, I really hope that iplot continues to work :) On a side note, I still need to call init_notebook_mode. This may be a transient issue. Thanks again |
You're welcome. I'm a little unclear about whether you're suggesting that we change the current functionality or not. If you use |
What I would really like is to be able to nbconvert a notebook containing ipywidgets (e.g. plotly figures) to HTML and the widgets still working interactively in the exported HTML. If I understand correctly, there are two issues:
It is not clear to me how this would be overcome. To my mind, though, this would be great. We create these notebooks that contain interactive content and it is great for handing in student work and for online presentation, but if the interactive content is shorn on export, then it sort of defeats the purpose. |
Maybe I am really just asking for Dash. if so, excuse my ignorance. |
What you want is possible, using this PR #900 which is not merged yet. Please test it out if it works for you. |
Thanks. This seems to bring me much closer, but something is odd. Having downloaded and installed your version of nbconvert, it works beautifully for Plotly plots containing webgl, but not for simple scatter plots? Also, it seems that I need to do
Should it work with any FigureWidget? If so are there known gotchas? |
A more detailed analysis. I downloaded the commit as a zip from GitHub and as mentioned, things are fine for my WebGL plots, but if I add a simple scatter plot things go wrong. This is a minimal example:
This works for me as long as I leave out the /Andreas
|
@maartenbreddels How does this PR work? I see that it involves the widget state, but how does it render widgets when targeting HTML output? |
Perhaps it's a different issue, but |
One workaround for import plotly.offline as py
import plotly.graph_objs as go
mesh = go.Mesh3d(x=[0,1,0],y=[0,0,1],z=[0,0,0],i=[0],j=[1],k=[2],flatshading=False,color='#333333')
py.iplot(go.FigureWidget([mesh]))
|
@gnestor thanks for the workaround, it works. |
Hello: This is the html where the plotly object is in blank, whether I export it from the book or using nbconvert from the console, the result is the same: If I save the graph using Here is some information of my system: Thank you in advance for any help. |
@pakinja See my workaround above. If the plotly R library doesn't provide an equivalent to the Python library's |
Documenting my attempt to understand the situation of this issue with the upcoming Plotly 4.0.0, using the most up-to-date instructions on how to enable Jupyterlab support: Ignoring a) Letting just (Note that Even without changing the default renderer nor temporally overriding it, as explained in the renderers documentation, both I tested this authoring the notebook on Jupyterlab, which has an option to save widget state automatically and therefore avoids common pitfalls. @gnestor @jonmmease Am I missing anything here? |
Hi @Juanlu001, Letting the Also, for docs that will always be viewed online, it might be a good idea to use the |
import plotly.offline as py autosize =False py.iplot(fig) instead of fig.show() worked for me. |
pio.show(fig) still does not show the plot after converting the notebook to HTML, is there anything else you are doing on top of that? |
A lot has changed in one year, I haven't been hit by this since then. It's a bit difficult to stay up to date with Jupyter, Jupyterlab, widgets and all the other components of the ecosystem :) I think it's easier if folks having this particular issue provide their own debugging information, using the latest version of everything if possible (in particular, using the new Plotly renderers instead of |
Hi, What worked for me was to add the correct renderer to the show instruction:
There are quite a few renderers, more info in here: |
@gnestor thank you for the advice. I had the same situation recently, but the usage link(https://github.com/jupyterlab/jupyter-renderers/tree/master/packages/plotly-extension#usage) no longer exits. Could you please give a new one? |
This works well, but the resulting file size is very large because plotly gets embedded in the HTML. If you are good with a static image in the HTML you can get it with a lot smaller file size by doing this: from IPython.display import Image
Image(fig.to_image()) |
Hi, I am having similar issues when exporting notebooks to html, but using the --TagRemovePreprocessor options of nbconvert. Without the TagRemove option plotly plots show correctly in the html file, but as soon as I have a few cells tagged for removal, all plotly plots show as blank on html. A full export command would be something like: jupyter nbconvert --to html my_notebook.ipynb --TagRemovePreprocessor.enabled=True --TagRemovePreprocessor.remove_cell_tags="remove-cell" I have attempted the solutions/workarounds proposed here, but without success. Any extra advice on this matter? |
Dear NBConvert developers
CC @gnestor
If I convert the following notebook to html, the output html file does not contain any graphics output.
However, if I use the old-fashioned:
everything works fine. It does not matter if I export from within Jupyter Lab or if I export from the command line with
jupyter nbconvert --execute --to html something.ipynb
My environment is MacOS 10.14.2, running Python 3.7 with
jupyter 1.0.0
jupyter-client 5.2.4
jupyter-console 6.0.0
jupyter-core 4.4.0
jupyterlab 0.35.0
jupyterlab-server 0.2.0
jupyter nbconvert 5.4.0
It seems that nbconvert has not been brought up to speed with the latest Plotly.py, i.e. > 3.0
I would be most grateful if this were fixed :-)
The text was updated successfully, but these errors were encountered: