31

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.)

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
chentingpc
  • 1,283
  • 3
  • 18
  • 24

8 Answers8

17

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:

Screenshot of jupyter read-only mode

Aurèle
  • 12,545
  • 1
  • 31
  • 49
blahblahetcetc
  • 191
  • 1
  • 6
13

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.

Tanu
  • 1,503
  • 12
  • 21
  • 2
    nbconvert: don't want to convert it every time I want to read some notebook and delete the converted version afterwards. – chentingpc May 10 '16 at 18:00
  • 1
    nbviewer: can it be used locally as easy as "ipython notebook mynb.ipynb --read-only", and not include other overhead? – chentingpc May 10 '16 at 18:01
  • ipython notebooks are not stored in human readable format. Also there is no version control for notebook. So you need to export HTML for a latest readable format – Tanu May 10 '16 at 18:10
  • 1
    nbviewer: Its a free public webservice. You can try Mozilla Addon - https://addons.mozilla.org/en-US/firefox/addon/open-in-nbviewer/ for you ease – Tanu May 10 '16 at 18:12
  • Not tried though - Refer http://stackoverflow.com/questions/16409774/is-it-possible-to-host-nbviewer-locally for local setup of nbviewer – Tanu May 10 '16 at 18:15
  • 1
    Also , you can write a python script which would auto-generate the HTML file automatically when ipython notebook is modified . – Tanu May 10 '16 at 18:17
  • nbviewer (even locally) still requires you go from web browser, but more naturally you would go from folder or terminal. I just think it is much better integrated into ipython notebook original functionality, though hacking using python script is possible. – chentingpc May 10 '16 at 18:23
  • Not sure about any integrated functionality yet ! Custom python using python subprocess module can be hack – Tanu May 11 '16 at 06:32
  • Someone could build a local viewer which uses nbconvert to produce a static HTML view whenever you open it. It just hasn't been done yet ;-) – Thomas K May 11 '16 at 10:27
  • For a simple viewer, written in Python, of ipynb-files, please see my answer to this question: [A simple way to view ipython-notebook](https://stackoverflow.com/questions/48481290/a-simple-way-to-view-ipython-notebook) . – user2320292 Dec 20 '19 at 10:26
13

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.

Denis Rasulev
  • 3,744
  • 4
  • 33
  • 47
3

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.)

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
0

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).

Holger Brandl
  • 10,634
  • 3
  • 64
  • 63
0

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

clockware
  • 21
  • 5
0

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.

Sabarish
  • 862
  • 1
  • 14
  • 23
0

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.

Jithin Johnson
  • 352
  • 1
  • 10