Save Jupyter notebook before nbconvert - command-line

I want to export a jupyter notebook within the notebook itself and use this command:
!jupyter nbconvert --to html MyNotebook.ipynb --output MyNotebook.html
This works correct, except that I manually need to save the notebook first for the latest outputs to be in the final html copy. Is there a similar command to save the notebook first (like hitting the save button) before doing the nbconvert?

import IPython
%%javascript
IPython.notebook.save_notebook()

Related

Term "Jupyter" not recognized as the name of a cmdlet, ... in VS CODE exporting PDF

I am trying to print a jupyter notebook file with the export button or this command:
jupyter notebook --to PDF test.ipynb
I have tried HTML, and it also doesn't work
I have installed:
MikTex
Pandoc
nbconvert
PIP
Jupyter

Jupyter Notebook "hidecode" tag not working?

I am trying to use the hidecode tag as shown here, but for some reason, it's not working on my local Jupyter Notebook server. The code remains visible, and no button on the right of the cell is displayed. I even downloaded the same notebook used in the page above, no dice.
I am running Ubuntu 18.04.2 LTS, Jupyter Notebook Server 5.2.2, Python 3.6.7, and IPython 5.5.0. The command I ran to start the server is sudo jupyter notebook --allow-root.
If you need any more info, please let me know. I appreciate any help I can get in figuring this out.
If you want to hide the code, the output or the prompt of your cells you can install the hide_code extension:
https://pypi.org/project/hide_code/0.2.0/
Stop jupyter
Run these commands
pip install hide_code
jupyter nbextension install --py hide_code
jupyter nbextension enable --py hide_code
jupyter serverextension enable --py hide_code
NOTE: I run the first two commands as root and the last two with the same user used to launch jupyter.
Restart jupyter
I found this extension very useful because I needed to print the notebook to a pdf file and all the tools like nbpublish, nbconvert was failing. In this way I can print the notebook directly from the "print" feature of the browser.

Invoking pyspark with `ipython` specified results in jupyter notebook being launched

I prefer using the ipython enhanced REPL over the python and so am specifying as such in the pyspark command line:
Result: jupyter notebook launched (surprising):
PYSPARK_DRIVER_PYTHON=ipython MASTER="local[*]" $SPARK_HOME/bin/pyspark
This approach was working for several years - but at the present it is causing jupyter notebook to be launched.
That result would make sense if the explicit command notebook were also present:
Result: jupyter notebook launched (expected):
PYSPARK_DRIVER_PYTHON=ipython notebook MASTER="local[*]" $SPARK_HOME/bin/pyspark
Given that the notebook is not specified then why is the notebook launched instead of the REPL ?
Note: when using ipython alone on the command line via
Result: ipython REPL launched (expected):
ipython
the REPL is launched (and not the jupyter notebook).
you might have set PYSPARK_DRIVER_PYTHON_OPTS variable to "notebook". this will cause to open jupyter notebook

jupyter nbconvert doesn't save actual output

I have a notebook script that I run on different datasets. I want to save the script, INCLUDING the output cells, in the data folder each time I run it.
I have the following command placed at the end of my script that I run in jupyter. I intend to save pretty much what I can see on the screen to a HTML file.
"here is my notebook script with inputs and ouput including graphs"
cmd='jupyter nbconvert --to html odnp_postprocessing.ipynb --output-dir '+dataFolder
os.system(cmd)
However, nbconvert does not export the actual cells. It will print out only the input cell without ouput the first time I run, but if I re-run, it will finally export both input and output. However then if I change something in the script, it will always export the first version. Then the only way around I found is to restart the kernel and re-run (twice) the new script with the modification.
Basically, it looks like nbconvert exports some kind of buffer that is not necesseraly the actual input and ouput cells that the user sees.
What I want to do, which is programmatically saved my notebook (inputs and ouputs) into HTML, each time I run it.
Is there a command to save the current version of the notebook? I tried to add %notebook before nbconvert command but a whole bunch of old inputs are saved as well.
I know I can run the notebook within nbconvert, but I'd like to avoid it as I already run it manually in jupyter.
Any idea?
I'm using jupyter through enthought canopy in Chrome browser.
Thanks
You're not telling us exactly how you are running nbconvert; from the current notebook ? Thus it is hard to figured things out.
Nbconvert converts the current file as it is on disk; as a wild guess: you haven't save your file. If you do not save your file then nbconvert will likely not have access to the outputs of cells; and wild guess again when you run it a second time autosave have kicked in.
Remember:
- Nbconvert does not execute the file
- Nbconvert is a separate process it can't magically access what is in your browser, which is potentially a different machine.
Usually think of it this way:
Run the notebook;
Save the notebook
Close the notebook
Run nbconvert.
reopen the notebook.
If you are using this command at the end of a notebook to save it in another format, then what you are looking for are save hooks that will trigger some code – server-side – every time you save a notebook.
Side note, learn about how to run shell command in IPython; ! can be used to execute shell command in CWD and does variable interpolation.

How do you install reveal.js so that jupyter and nbpresent can use it?

I'm experienced with IPython Notebook but just upgraded to Jupyter 4 with nbpresent, and I want to use reveal.js for slideshows.
How can I incorporate reveal.js into my notebook slideshow?
The most common way to do this is using nbconvert:
jupyter nbconvert presentation.ipynb --to slides --post serve
For more information, see nbconvert documentation.
You would only use RISE if you need to execute commands on the kernel during the presentation.