I'd like to save a notebook (like clicking the "disk" icon in the toolbar) via a code block. Reason: I'd like to use nbconvert
via a %%bash
magic to save HTML and slide versions, but that converts what's on disk, not what's running.
I'm not looking to do this every time I save (for which I see some config that can be set up), but only selectively for some of my notebooks. I'm looking to be able to "Run All" and have the last few cells create the additional files reflecting the fresh data on screen at the moment.
I've tried %save
and %notebook
magics, but neither does quite what I'm looking for (the best I can tell).
Is there any way to do this?
You can use this Jupyter extension By default, a Jupyter Notebook saves your work every 2 minutes, and if you want to change this time interval you can do so by using the %autosave n magic command; where n is the number of seconds, and if n=0 this means no autosaving.
Saving your edits is simple. There is a disk icon in the upper left of the Jupyter tool bar. Click the save icon and your notebook edits are saved.
Open the jupyter notebook that you want to convert. Navigate into the 'File' menu and select 'Download as'. The more options will be displayed in the form of a list where you will click on the 'Python (. py)' option.
Double-check the settings at "Settings" -> "Site" and make sure "New notebooks use private outputs (omit outputs when saving)" is disabled. Similarly, check also "Edit" -> "Notebook settings" and make sure "Omit code cell output when saving this notebook" is disabled.
A hacky way to do it is using the %%javascript
notebook magic to run the command
require(["base/js/namespace"],function(Jupyter) {
Jupyter.notebook.save_checkpoint();
});
This accesses the global notebook instance (when on the notebook page this is the current notebook) and manually triggers a save and checkpoint.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With