How to Make a Portable Jupyter Slideshow - python

How do I make a Jupyter slide show portable? I can serve the slideshow locally, but I can't send that to anyone and have it work with all the images, slide animation functionality, etc.
I am using jupyter nbconver my_notebook.ipynb --to slides and get a simple linear html file that depends on the files being on the machine where the file is used.

You should specify --reveal-prefix to convert it, nbconvert doc.
jupyter nbconvert my_notebook.ipynb --to slides --post serve --reveal-prefix "http://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.3.0"
You may also use a local Reveal.js library, see here.
If you want a PDF, add ?print-pdf to the address of the running html, like:
http://127.0.0.1:8000/my_notebook.slides.html/reveal-js?print-pdf
Then save(print) it as pdf.
You may also want to have a look at nbpresent.

Related

View Jupyter notebooks hosted on Sharepoint

In our institute, we use OneDrive / Sharepoint from Microsoft to share files with each other. I am also sharing my Jupyter notebooks - with extension *.ipynb - there. Unfortunately, when one clicks on such a file the message "Hmm... looks like this file doesn't have a preview we can show you" appears. In my case I developed my notebooks with python. It's not necessary that my colleagues can run the notebook, but it would indeed be much easier to be able to install a kind of plugin for previewing on the Sharepoint server. Is there any product that can work like this? Otherwise I'll have to always export the file to HTML or so :-(
Unfortunately, there isn't any good news so far. Such a plugin seems to be unavailable as yet. For the meantime, I have automated the exporting of the notebooks to HTML on my Windows 10 machine as follows:
For /R .\ %G IN (*.ipynb) do jupyter nbconvert --to html "%G"
For use in a *.bat file, you'll have to double the %-signs.

How to export standalone (HTML) Jupyter notebook with TOC and collapsible headers

I am using Jupyter notebooks to create interactive web reports for my job. Reports are fairly extense, so I would like to setup a TOC for easier navigation. I am aware of the extension that exists for this matter, but I would also like to have collapsible header synchronized with my TOC. All works great when running the notebook locally, but when exporting to HTML I have to choose between collapsible headings or TOC.
Note: To export the notebooks I am using the jupyter nbconvert --to html_ch Untitled.ipynb for collapsible headings and jupyter nbconvert --to html_toc Untitled.ipynb for TOC.
Does anybody know if it is possible to "combine" both exporters and if it is, how?
This is verbatim from here. It is not possible to use multiple exporters at a time. But you could get the desired effect
jupyter nbconvert --to html_embed --template toc2 FILE
Otherwise, if what you want/need is to keep image files in the html (html_toc extracts the image since the extractPostprocesor is enabled in toc2.py -- may not be a good idea after all), you can issue
jupyter nbconvert --to html_toc --ExtractOutputPreprocessor.enabled=False FILE
The second one should work.

Convert ipynb notebook to HTML in Google Colab

I have a Google Colaboratory Notebook for Data Analysis that I want to output as a HTML file as currently not everything loads within the Colab environment such as large Folium Heatmaps. Is it possible to export the notebook as a html file as opposed to the ipynb and py options?
Method using Google Colab only
Download your .ipynb file
You can actually do it using only Google Colab. File -> Download .ipynb
Reupload it so Colab can see it
Click on the Files icon on the far left:
Then Upload to session storage:
Select & upload your .ipynb file you just downloaded.
Get your file's path
then obtain its path (you might need to hit the Refresh button before your file shows up):
Conversion using %%shell
Then, just as in Julio's answer, execute in a Colab cell:
%%shell
jupyter nbconvert --to html /PATH/TO/YOUR/NOTEBOOKFILE.ipynb
The %%shell lets the interpreter know that the following script is interpreted as shell. Don't write anything before %%shell, use a distinct cell for this.
The form of /PATH/TO/YOUR/NOTEBOOKFILE.ipynb will be something like /content/lightaberration3.ipynb.
Your file is ready
Might need to click Refresh again, but your notebook.html will appear in the files, so you can download it:
The great thing about this is that nothing python-related has to be installed on your computer, not conda, not pip, only a browser.
Google Colab doesn't currently have such a feature as a built-in.
Your best route is to first download it through File > Download .ipynb and then use the standard tool for Jupyter Notebook conversion, nbconvert:
jupyter nbconvert --to html notebook.ipynb
If you use an Anaconda Python distribution, nbconvert is most likely already installed. If not, refer to what is described in their install instructions to be able to convert:
pip install nbconvert
# OR
conda install nbconvert
to continue with "Method using only Google Colab"
" %%shell jupyter nbconvert --to html /PATH/TO/YOUR/NOTEBOOKFILE.ipynb" - as given
the following worked for me - type the following in Google Colab
!pip install nbconvert
%shell jupyter nbconvert --to html /content/testfile.ipynb
(instead of using %%shell in Google Colab, use %shell - this way, it worked for me)
Download your notebook and upload it back to the colab
Replace PATH_TO_THE_NOTEBOOK_IN_COLAB in the below command to the location of the reuploaded notebook.
Use this command to download the notebook as html => !jupyter nbconvert --to html PATH_TO_THE_NOTEBOOK_IN_COLAB.ipynb.
I tried the approach above but couldn't get it to work - for small jobs I log onto https://jupyter.org/try , upload the downloaded ipynb file from Google Colab and then I opened the file, from here you will have the functionality in jupyter.org to download as html or whatever other format you require. It took the pain out of trying to get it to work.

How to embed pdfs files in jupyter notebook on Github

So I have few pdfs files which I uploaded to my repository on Github. Now I am uploding a jupyter notebook file in the same directory as the pdf files on github and want to display pdfs inside the jupyter notebook.
I used the following method to embed pdfs in a notebook.
from IPython.display import IFrame
IFrame("https://github.com/user/first.pdf", width=900, height=800)
Now the same thing works when I do this on my local laptop where I store the pdfs in a directory and link that to the jupyter notebook file on my laptop. I can see the pdfs inline too.
However when I do the same thing on Github, it doesn't show the pdfs and get the following thing:
So am not sure why it is not able to link the pdfs stored on the same repository on github and display them while it works on my local system
Any help?
Thanks
In the case of Github, it is because of X-Frame-Options restriction.
See: iframe not rendering in ipython-notebook
As a workaround, you can try using rawgit.com:
Example:
https://raw.githubusercontent.com/mozilla/pdf.js/raw/master/test/pdfs/S2.pdf (does not work)
https://rawgit.com/mozilla/pdf.js/master/test/pdfs/S2.pdf (works)

Open IPython notebooks (*.ipynb) in read-only view (like a HTML file)

Nowadays with more and more IPython notebook files (*.ipynb) around, it is very disturbing every time when I want to peek at some notebook I have to open a server for it, and cannot do it in read-only mode. Due to auto-save I can accidentally change the file when reading it if not in read-only mode.
I hope something like this: ipython notebook mynb.ipynb --read-only would work, but sadly it doesn't (although still it creates a server which I don't really want in read-only view). What I really want is to open an ipynb file like a HTML file for reading; currently it seems a missing view of ipynb file, and now the notebook is more like a black-box or near-binary file alone.
(P.S. I am using Linux/Ubuntu.)
When you change the notebook files' permissions, jupyter's auto-save doesn't touch them:
chmod a-w *.ipynb
Then jupyter goes into read-only mode:
Try this ipynb Viewer. This renders ipython notebook as a static web-page.
Also ypu can convert ipyhton notebook to other formats using
ipython nbconvert --to FORMAT notebook.ipynb.
Refer Convert Ipython notebook to other formats. Using this you can convert ipython notebook to HTML.
You may also want to try nteract app (https://nteract.io)
nteract is a desktop application that allows you to develop rich documents that contain prose, executable code (in almost any language!), and images.
Here you can find more detailed review of the app.
It is completely free and very convenient tool by itself and I use it quite often to see other ipynb files if needed and for quick development.
The best I can suggest - unfortunately still a bit verbose - is using nbconvert to create a HTML version of the file, then opening it with your browser. Below are commands to do this (assuming that your browser is set up as the default program to handle .html files). Just replace yournotebook.ipynb with your real Notebook name.
Linux
jupyter nbconvert --to html yournotebook.ipynb --output /tmp/notebook.html &&
xdg-open /tmp/notebook.html
macOS
jupyter nbconvert --to html yournotebook.ipynb --output /tmp/notebook.html &&
open /tmp/notebook.html
Windows
jupyter nbconvert --to html yournotebook.ipynb --output "%TEMP%\notebook.html" && start "" "%TEMP%\notebook.html"
(Note that if you want to do this in bulk, perhaps in a loop in a script, you'll probably want to modify the commands above to not always use the same filename for the HTML file, to avoid the race condition where the HTML file has been overwritten by the time the browser actually gets round to starting to read it.)
Intellij IDEA (which is also available as free open-source community edition) can render ipynb files as well. In fact it also allows to author notebooks, so it's not just a viewer.
It can be used via file type associations or via the command line launcher (e.g. idea foo.pynb).
I use Github Gist for that. You'll need a Github account.
If you specify *.ipynb file extension there for your content copy/paste, it'll detect it and format as html view. You'll be able even sharing it with someone using link if that's interesting. No tools required other than having a browser.
I've found some glitches in formatting though, mostly with output plots, but it's reasonably rare.
Random example here: https://gist.github.com/Clockware/aa7e01722579841d5888ca83385a5f1d
I was able to read .ipynb files as html in visual code. You would need a python plugin for it which visual code auto detects. Fairly straight forward after that.
This most convenient method to take a peek at jupyter notebooks is by using nb-viewer, with this utility, you will be able to open notebooks (in read-only mode) with a double click.

Categories

Resources