MyST-NB icon indicating copy to clipboard operation
MyST-NB copied to clipboard

Gluing HTML outputs as figures

Open bmcfee opened this issue 4 years ago • 6 comments

Is your feature request related to a problem? Please describe.

Gluing a matplotlib animation as a glue:figure directive doesn't work, in that no animation content is rendered in the final webpage, and it shows up as an empty figure (with index and caption, though).

Describe the solution you'd like I would hope that rendered animations (via their repr_html) could be embedded inside a figure.

Describe alternatives you've considered I'm hacking around it for now by displaying the rendered animation in an output cell immediately above the figure glue reference, eg:

---
display(animation)
---

---
```{glue:figure} refname

Caption goes here
```
---

This ends up looking almost right, and it does increment the figure counter and show the caption, but I worry about things like reference anchor positioning and the like.

Additional context N/A

bmcfee avatar Jul 10 '20 23:07 bmcfee

If I read this correctly - it sounds like the feature request is more like "glue HTML outputs as figures" rather than matplotlib animations per-se, is that right? (e.g., if the matplotlib animation was a gif this would still work fine right?)

choldgraf avatar Jul 13 '20 15:07 choldgraf

it sounds like the feature request is more like "glue HTML outputs as figures" rather than matplotlib animations per-se, is that right?

In retrospect, yes, exactly. I've since switch to the jshtml output instead of html5 video, but the underlying issue is the same in both cases.

bmcfee avatar Jul 13 '20 15:07 bmcfee

ok cool - I'm gonna change the title here. I think it's a good idea to support as more and more visualization libraries use HTML in their outputs and maybe (one day, in like a million years) journals will support this

choldgraf avatar Jul 13 '20 15:07 choldgraf

I have been trying to glue the output from plotly, which is also rich html and javascript. However, in my document I get no output (not even the static png fallback). I assume that this is due to the same issue discussed above.

DavidPowell avatar Aug 05 '20 01:08 DavidPowell

I'm also having the same issue with plotly, I've tried a couple workarounds but so far haven't been able to get it to display.

adityarao-freenome avatar Jun 22 '22 20:06 adityarao-freenome

For Plotly and Holoviews I've had some success with a - rather hacky - glue wrapper which is currently providing "rich" figures for HTML outputs and static renders for PDF builds. See https://github.com/executablebooks/jupyter-book/issues/1815#issuecomment-1426236893 for the code and more details... it's not great, but will hopefully be useful for anyone else having these issues at the moment.

phockett avatar Feb 10 '23 20:02 phockett