mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.63k stars 385 forks source link

Option to save notebook as reveal slides (.html) #575

Open Bubblbu opened 4 years ago

Bubblbu commented 4 years ago

Jupyter notebooks currently support the conversion to reveal slides (.html). However, I haven't found a way to neatly use this feature while working on a notebook.

Currently, you have to export the notebook as an html file which is downloaded trough the browser (typically your file will end up in your Downloads folder). As I am also hosting those slides on Github, I now have to move that file around manually.

Instead, I'd love to sync the current notebook with the html file in the current folder. I assume that I could somehow find a solution with a custom script that uses nbconvert automatically, but I was wondering if this would be something that jupytext could (or would) support.

mwouts commented 4 years ago

Hi @Bubblbu , I have no plans to parse html files into notebooks yet 😄, so unfortunately the answer is not through jupytext.

Still, I think you could achieve the automated sync with the HTML slides with a post_save_hook.

Take inspiration from https://gist.github.com/ceshine/2a68a96e7a9f72551d00c5578249340f or https://github.com/jupyterhub/jupyterhub/issues/1412. That should be compatible with Jupytext, although maybe you will have to specify explicitely c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager" in your configuration file.

cc @damianavila and @parmentelat, in case they are already aware of a RISE-specific post_save_hook.

parmentelat commented 4 years ago

Hey @Bubblbu

Are you aware that rise lets you display your notebook under reveal without leaving your classic notebook session ? Can you please elaborate on the reasons for your need of a html file in the first place ?

Bubblbu commented 4 years ago

Hi @mwouts,

thanks for the pointers to the post_save_hooks. that does indeed sound like the right place to look for this :) it looks like these hooks would then be applied to my overall notebook config instead of singular notebooks, no? Which is why I was thinking of a jupytext-like solution. I would only need this very selectively and I already super used to the easy syncing with Jupytext which is why I posted here :D

@parmentelat This is mostly for sharing and collaboration purposes (also, it's nice as an open science/open data practice imo). I'm the main developer on the team and we've been using notebooks for internal reports already, but I wanted to try using notebooks for actual slides as well. It seemed like a pretty neat way of achieving reasonable

parmentelat commented 4 years ago

Hi

I was not asking about the relevance of creating slideshows out of notebooks of course My point is that rise allows to do just that out of the box, and was asking for why you think you need to pass by the html as an intermediate format

Bubblbu commented 4 years ago

Ok, just had a look at RISE (wasn't familiar) and I think that I'm already using it via the JupyterLab/notebooks interface.

However, the question becomes how to share those slides with collaborators who are not familiar with the jupyter universe or programming. My current approach (for simplicity) was to simply setup Github Pages on the master branch of the repository and point my team members to the html file hosted on Github.

Hope this addresses your questions

parmentelat commented 4 years ago

Oh I see; I do not know of any way to automate that workflow from within RISE either

mwouts commented 4 years ago

Hi again,

it looks like these hooks would then be applied to my overall notebook config instead of singular notebooks, no?

Oh I see. Well, in the pre_save_hook we have access to the notebook content, so maybe there we can decide, based on the presence of RISE metadata, whether to export the notebook to HTML or not.

If you like the idea, I can give a try at writing such a pre_save_hook at some point next week, share it in the form of a gist, and then we iterate based on your feedback.

damianavila commented 4 years ago

Folks, I think there is a confusion here in terms of the difference between static slides produced by nbconvert (and producing the html file that @Bubblbu is mentioning above) and the live slides created "on the fly" by RISE (where there is not an html file output). I just want to be sure anyone in this conversation is aware of that difference to prevent talking about different things ;-)

Btw, if we are talking about the nbconverted static slides, I think the pre_save_hook is the way to go here at first... and if jupytext wants to go further, then great! (although I think the hook should be enough).

mwouts commented 4 years ago

Folks, I think there is a confusion here in terms of the difference between static slides produced by nbconvert and the live slides created "on the fly" by RISE

Oh thank you @damianavila for pointing this out. I was not aware that there were Notebook slides other than RISE :smiley:

So then this issue is only about running jupyter nbconvert --to slides or an equivalent Python command, on some selected notebooks.

@Bubblbu, how do you suggest to decide whether a particular notebook should be exported, or not, to HTML slides? For instance, do you use some specific cell or notebook metadata in these notebooks?

Bubblbu commented 4 years ago

Thank you @damianavila for clarifying things! I wasn't aware of the RISE background and probably wasn't clear about what I was referring to.

But yes, @mwouts, it's basically about accessing the nbconvert endpoint for slides. As for the decision to convert or not, as far as I can see, the only metadata that specifies the conditions for a slideshow are embedded in individual cells by defining a value for slideshow. E.g.,

{
    "slideshow": {
        "slide_type": "skip"
    }
}

Do you have any thoughts on whether this might lead to performance issues? I have no experience at all with playing around with hooks for notebooks. I'd think that even a small performance lag in terms of saves might be quite disruptive to the overall notebook experience? But again, not very familiar with these things.

I do think, that a jupytext like solution would be more elegant as we would have explicit conditions for conversions rather than relying on metadata (so if anyone here likes this idea I'd still be very excited to see this implemented :crossed_fingers:)

mwouts commented 4 years ago

Hi @Bubblbu , that was a great idea! I've written such a save hook in this gist, and I am using it now to prepare some slides, indeed that is very useful.

parmentelat commented 4 years ago

Hi all

that sounds like a great addition indeed; I can volunteer to pour this into the code of rise if there's interest; in particular rise already has some provisions in the (js) code to determine if a notebook is a slideshow (in particular in the context of the autolaunch feature), so it would make sense to factor this sort of heuristics in a single place - although maybe not everyone potentially interested is a rise user, please feel free to comment on that

I take this chance to ask if there are means to adopt such a hook on a notebook-per-notebook basis, through metadata or similar ?

one thing though that I think must be stressed, as @damianavila pointed out already, is that there are at this point some features of rise that have been implemented in such a way that they won't make it to a nbconvert output; and I'm the one to blame for that since at that time I was not enough aware of nbconvert (I don't think I've ever run nbconvert to produce slides…) and the related constraints; among those, things like customizable background or header/footer; and probably a few others that have dropped off my RAM

not that it alters anything about the interest of such a hook, but just making that plain again so that everybody is in sync on the existence of the possible discrepancy

westurner commented 4 years ago

It would be very helpful to be able to install this feature without needing to modify a python file for every installation. Would RISE then have a dependency upon jupytext? Is RISE necessary to utilize this jupytext functionality?

What is possible with static RISE reveal.js slide outputs? Could cells be run with a configurable kernel w/ e.g. thebe? And/or, Would it be necessary to pass a repo URL & nb path to a binderhub server such that a container with the appropriate dependencies could be provisioned?

westurner commented 4 years ago

Where would be the appropriate forum to discuss the intersection between RISE and jupterbook (and jupytext) in terms of features?

Could JupyterBook have a 'View as RISE slides' option which utilizes thebelab+mybinder.org for interactive code execution?

Could Jupytext save as RISE slides if RISE refactors onto nbconvert as much as possible?

/cc @choldgraf

choldgraf commented 4 years ago

just a note that we have a few discussions around this in jupyter book as well, here's the most general one:

https://github.com/executablebooks/meta/issues/52

mwouts commented 4 years ago

Thanks everyone for these inputs ! Well I am sorry I can only address a subset of all of the questions here :smile:

I take this chance to ask if there are means to adopt such a hook on a notebook-per-notebook basis, through metadata or similar ?

Well the hook is active only for the notebooks that have a slideshow metadata on at least one cell.

Do you have any thoughts on whether this might lead to performance issues?

I've used a pre_save_hook rather than a post_save_hook, the difference being that we do have the notebook in the hook, so we don't need to read it from disk, so I expect no performance issue at all for notebooks that are not slides, and only a very reasonable impact on the notebooks that are exported as slides.

It would be very helpful to be able to install this feature without needing to modify a python file for every installation. Would RISE then have a dependency upon jupytext? Is RISE necessary to utilize this jupytext functionality?

The hook is independent of both RISE and Jupytext.

there are at this point some features of rise that have been implemented in such a way that they won't make it to a nbconvert output;

Well, that should not be an issue, I think you just need to modify this line: https://gist.github.com/mwouts/04a6dfa571bda5cc59fa1429d130998f#file-jupyter_notebook_config-py-L56

I do think, that a jupytext like solution would be more elegant as we would have explicit conditions for conversions rather than relying on metadata

Well, I agree. Still, there is a difference between the existing Jupytext formats and slides: slides are an export-only format, and ATM we don't have export-only formats in Jupytext. Maybe we could change that in the future if that proves helpful, but I'd prefer to think a bit about that first.

Bubblbu commented 4 years ago

Hey @mwouts, thank you so much for implementing the gist (and happy to hear that you're also happy with this particular use case :D). I'll definitely be using this as my go-to solution for intermediate reports based on prelim data/analyses.

Well, I agree. Still, there is a difference between the existing Jupytext formats and slides: slides are an export-only format, and ATM we don't have export-only formats in Jupytext. Maybe we could change that in the future if that proves helpful, but I'd prefer to think a bit about that first.

this makes a lot of sense especially if it would mean introducing a completely new kind of output. thanks for the quick responses (and the gist obvs) though!

IMO the original issue has been addressed. Feel free to close this issue (and maybe move the other convos into more specific ones?)

psychemedia commented 3 years ago

@mwouts Re:

I have no plans to parse html files into notebooks yet

there's an old demo of recreating a notebook .ipynb file from exported HTML here.