jupyter-xeus / xeus-octave

Jupyter kernel for GNU Octave
https://xeus-octave.readthedocs.io/
GNU General Public License v3.0
57 stars 10 forks source link

Does not export plotly to HTML #108

Open lucasmsoares96 opened 1 year ago

lucasmsoares96 commented 1 year ago

First of all, you guys are doing an amazing job here.

Description

I would like to export a notebook to HTML that contains a plot using graphics_toolkit("plotly"), but the plot does not appear in the generated HMTL. If you use graphics_toolkit("notebook") it works fine. For a Julia notebook the interactive graph is exported normally to HTML.

What I Did

graphics_toolkit("plotly")

[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surf(X,Y,Z)

Then: File > Save and Export Notebook As... > HTML

rapgenic commented 1 year ago

Hi,

Thank you for reporting!

I can reproduce what you're seeing, and I think the reason for this is that when plotly is active xeus-octave produces an output with mimetype application/vnd.plotly.v1+json, which is automatically rendered by jupyterlab without intervention from the kernel.

I don't know about Julia, but I tried Python, and I found out that when showing a graph it outputs a text/html mimetype (in addition to the application/vnd.plotly.v1+json) which contains a pre baked html representation (made by the kernel) of the plot (bundling the plotly.js library and other things, already minified).

Unfortunately, at the moment the same thing is quite complicated to do for xeus-octave, because it cannot easily handle all the plotly libraries and prepare an html representation inside the kernel, so we must rely on jupyterlab doing this work for us.

I have seen that when you export to HTML, the plot is saved as an image, so it is probable that the plotly extension that jupyterlab uses for rendering the plot also gets to decide what format to output when exporting the notebook, so it might be possible to achieve what you need by adding an html output at conversion, but this goes beyond my knowledge.

Do you at least have the image output?