executablebooks / MyST-NB

Parse and execute ipynb files in Sphinx
https://myst-nb.readthedocs.io
BSD 3-Clause "New" or "Revised" License
210 stars 84 forks source link

Gluing HTML outputs as figures #212

Open bmcfee opened 4 years ago

bmcfee commented 4 years ago

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
choldgraf commented 4 years ago

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?)

bmcfee commented 4 years ago

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.

choldgraf commented 4 years ago

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

DavidPowell commented 4 years ago

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.

adityarao-freenome commented 2 years ago

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.

phockett commented 1 year ago

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.