For my educational project, I am inspired by this notebook series: https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python
When I open those notebooks on Binder, all the cells are run, I see all the plots.
But in my notebook, where I have a link to a video for example, the video only shows up when I run the cell. On opening the notebooks I just see the code of the cell. But I want my potential students to only see the embedded video.
from IPython.display import YouTubeVideo
How can I make my notebooks behave like the ‘Kalman-and-Bayesian’ one?
Run the cell once and save the resulting notebook. It’ll have the display outputs persisted in the document without the kernel having to recompute them. For displaying outputs only there’s some options but not all interfaces support them. e.g. nbextensions using these metadata keywords
I’m pasting a screenshot here of what I’m seeing when I open my notebook in Binder. I did run the cells, save, commit, push to my repo, launch from binder link. Simple code output does persist, but not video.
The output is blank. I need to run the cell again to see the clickable video thumbnail.
I do have a workaround which is to display the video from markdown when clicking on a thumbnail image, but that requires me to store the thumbnail image of the video
Have you considered using Voila via Binder, if you are trying to not require students to run code to see output? It freshly runs the code upon launch. I haven’t tried video in Voila, though. I see that indeed there is a video widget, see here. The example Voila pages launched from the Voila gallery are rendered via MyBinder as well.
Just saw this reply, thank-you haven’t tried those things, as I just now figured out that I need a postBuild file and I can put stuff there like enabling extensions, so I added jupyter trust … and it worked!!
I noticed that the metadata for the cell said ‘trusted: false’ in the Binder rendered notebook, but it was trusted in my local version.
I don’t understand how this works, and why 2*3 is run without trust but displaying a video is not, but happy I found a cleaner solution than my previous horrible markdown hack.
Glad you’ve found trusting is way to go to get what you need. (I wonder if that works for Plotly plots, too? --> UPDATE: it indeed does, see example here.)
Just to clarify something…
It isn’t re-running
2*3 when you launch a session and open your previously saved notebook via MyBinder. Just displaying the previously made output. Certain output isn’t handled upon reopening. I am assuming something did get saved in the output cell from the original run since it seems to make a space for when it isn’t trusted but you’d have to verify by looking at the output for that cell while viewing the notebook in a text editor. For example,
.png images displayed in an output cell via
from IPython.display import Image get saved as Base64 code upon saving the Jupyter notebook and you’ll see the image rendered when you reopen it. I don’t know what from video gets saved as in an output cell.
The notebook code is not re-run upon opening in general. That is why you can see most output instantly when opening the notebook on MyBinder.org. Voila can re-run code before it renders the output though.
Just as another handy trick, the
init_cell notebook extension looks like it can be used to autorun selected cells on notebook load.