Plotly graph does not show up when using the pdflatex builder
See original GitHub issueDescribe the problem
When I build a book with the pdflatex builder, plotly graphs are seemingly not included in the pdf by default. A workaround can be done to fix this by changing the plotly render method to png as follows
import plotly.io as pio
pio.renderers.default = "png"
but the pdflatex builder then expects the generated pngs to be in the root of _build\jupyter_execute. This is not the case if the .ipynb is in a subfolder of the book directory. In the case of the notebook being in a subfolder, the png is generated in _build\jupyter_execute\subfolder\ and therefor is not found by the builder
Link to your repository or website
No response
Steps to reproduce
Standard
- Create notebook with plotly graph
import plotly.graph_objects as go
ifig = go.Figure(go.Scatter(x=[1,2], y=[1,2]))
ifig.show()
- Create a toc and _config that includes
sphinx:
config:
html_js_files:
- https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js
- Build the book
jupyter-book build mybook\ --builder pdflatex
- Open the pdf and see that no plotly figure is present
PNG
- Create a notebook in a subfolder (mybook\folder\notebook.ipynb)
- Create plotly graph in notebook
- Add plotly renderer line to notebook
import plotly.io as pio
pio.renderers.default = "png"
- Build the book
- See the following warning in the build
WARNING: image file not readable: .../mybook/_build/jupyter_execute/notebook_15_1.png
- See that the file is not in this location and is rather in _build/jupyter_execute/folder/notebook_15_1.png
- Open the pdf and see that no plotly figure is present
The version of Python you’re using
3.8.5
Your operating system
Windows 10
Versions of your packages
Jupyter Book : 0.11.2 External ToC : 0.2.2 MyST-Parser : 0.13.7 MyST-NB : 0.12.3 Sphinx Book Theme : 0.1.1 Jupyter-Cache : 0.4.2 NbClient : 0.5.3
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (4 by maintainers)
thanks for this well documented issue @andrewellis55 – will take a look at this. (cc: @AakashGfude)
We haven’t explicitly built support for
plotly
into thepdflatex
builder as there are a lot of object types. Your suggestion to convert items topng
in the code is a solution I use a lot in house as well.Do you know if
plotly
returns apng
as an alternative representation in the executedipynb
? If it does you can change therender_priority
to use the png instead of the returnedjavascript
object.https://jupyterbook.org/content/code-outputs.html?highlight=render_priority#render-priority
Thanks for the update, I appreciate.
In between, I patched the 0.13 version by hand (it is really 2 lines) inside a container I will use for the final PDF generation.