GR.jl icon indicating copy to clipboard operation
GR.jl copied to clipboard

[BUG] Plots do not render from in html when exported .ipynb to .html

Open luboshanus opened this issue 3 years ago • 4 comments

Hi, (transferring here from Plots.jl, also asked at discourse)

when I export a julia notebook .ipynb to html it does not export GR.jl-created images well. They show in html as a svg code but are not well rendered. With PyPlot.jl figures show in .html as expected figures/plots.

I don’t know if the problem is with GR.jl, IJulia, or something within Jupyter-lab as nbconverter.

Using Julia 1.6.7

  [28b8d3ca] GR v0.69.5
  [7073ff75] IJulia v1.23.3
  [91a5bcdd] Plots v1.35.4

HTML file: Screen Shot 2022-10-20 at 16 00 15

Notebook: Screen Shot 2022-10-20 at 16 00 24

  [28b8d3ca] GR v0.69.5
  [7073ff75] IJulia v1.23.3
  [91a5bcdd] Plots v1.35.4

Output of versioninfo():

Julia Version 1.6.7
Commit 3b76b25b64 (2022-07-19 15:11 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin21.4.0)
CPU: Intel(R) Xeon(R) W-2150B CPU @ 3.00GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake-avx512)

also in:

Julia Version 1.8.2
Commit 36034abf260 (2022-09-29 15:21 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin21.4.0)
CPU: 20 × Intel(R) Xeon(R) W-2150B CPU @ 3.00GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, skylake-avx512)
Threads: 1 on 20 virtual cores

luboshanus avatar Oct 20 '22 14:10 luboshanus

This is not a problem in GR. Even simple SVGs can't be exported to HTML with recent notebook/nbconvert releases.

image

jheinen avatar Oct 21 '22 12:10 jheinen

Thanks. So, the solution for now is to downgrade notebook/nbconvert?

luboshanus avatar Oct 21 '22 13:10 luboshanus

I'm afraid so. But I don't know how many versions you have to go back. As a workaround, you can use using GR; inline("png") ...

jheinen avatar Oct 21 '22 13:10 jheinen

Downgrading nbconvert didn't work for me (might be because I'm trying to create slides with Reveal.jl). What ended up doing the trick (thanks to https://github.com/jupyter/nbconvert/issues/1836#issuecomment-1232536621) is was editing the base template located at: <installation prefix>/share/jupyter/nbconvert/templates/lab:

$ diff base.html.j2.old base.html.j2
166c166
< {{ output.data['image/svg+xml'].encode("utf-8") | clean_html }}
---
> {{ output.data['image/svg+xml'] }}

This will at least render the svg correctly until the folks over at https://github.com/jupyter/nbconvert/issues/1849 have fixed nbconvert.

JBlaschke avatar Oct 25 '22 23:10 JBlaschke