SVG either not loading right, or not exporting to HTML?

hi all,

Hopefully I’m posting on the right category – apologies if not.

I’m writing a new kernel and facing issues with displaying SVG:

  1. If I use display_data message with a mime-type image/svg+xml, it displays correctly, but when the notebook is exported to HTML the SVG content is displayed as text (the SVG code is displayed instead of the graphics).
  2. If instead I use display_data message with mime-type text/html and simply send the SVG (since it’s valid within HTML), it also displays correctly in the notebook, and exporting the notebook to HTML works. But, if one saves and reloads the notebook, the SVG is gone (forcing me to re-run the affected cells).

Any suggestions or work arounds ?

Many thanks!

Update: I tried loading the .ipynb with the SVG generate with method (2) above (embedded in an text/html display_data message) in Google’s colab, and there it displays the SVG when loading the notebook. This seems to indicate something specific to the jupyter-lab notebook’s loading ?

1 Like

For the (2) case, In JupyterLab, after re-opening notebook you may need to explicitly trust it to due to a bug discussed here: Jupyterlab not remembering trust for notebooks

To trust a notebook go to Command Palette and select “Trust Notebook”.

2 Likes

Many thanks @krassowski, it worked for case (2)! I didn’t know about “trusted notebooks” or that a “command palette” existed in Jupyter-lab.

1 Like