JohnPython
JohnPython

Reputation: 677

A simple way to view ipython notebook

I am really new to IPython/Jupyter notebook. I just created one notebook (.ipynb) and I want to share it on my webpage. Specifically, I want to add a link, and when people click it, it will open a new "webpage" where they can "view" my code and results.

Note: I cannot use github, it is a huge pain for me.

I tried nbviewer (http://nbviewer.jupyter.org/). It has several options but only one of them (url) is not related to github/gist. So, in order to have an URL for my file, I uploaded it to google drive, and got a public link for the file. On the other hand, when I put that link to nbviewer (as url to my file), it says "there is no file in this url". On the other hand, I know the link works, because when I put it on browser, it directs me to download the .ipynb file.

Upvotes: 48

Views: 144735

Answers (7)

pylang
pylang

Reputation: 44605

There appears to be limited non-GitHub options for sharing notebooks. You can still share a link directly from Google's colaboratory. This will allow you to:

  • Upload your file
  • Share the link with various permissions

Any Google user can view (and optionally edit) your notebook.


See also other options:

  • binder: sharing notebooks from a GitHub repo; (see related blog post)
  • nbviewer: for viewing hosted notebooks from GitHub or a url (as mentioned)
  • JupyterHub: hosting notebooks on a private server, e.g. local, DigitalOcean
  • Azure Notebooks: host notebooks on an Azure server (see sample notebook)
  • repo2docker: spawn docker container from a git repo of notebooks
  • commuter: read notebooks from a local directory or S3 service
  • cocalc: collaborative and share private notebooks
  • nextjournal: publish notebooks and save work as containers
  • Deepnote: real-time collaborative notebooks with simple setup
  • fastpages: convert notebooks/markdown to GitHub pages via GitHub Actions (thanks Björn)
  • DataCamp Workspace: real-time collaborative notebooks with built-in datasets and code templates

Upvotes: 51

sunfishstanford
sunfishstanford

Reputation: 41

VS Code has built in support for Jupyter notebooks.

Upvotes: 4

pplonski
pplonski

Reputation: 5859

If you want to share your Python notebook so others can view it, then you can try an open-source framework called Mercury. The Mercury converts notebook to a web app. Additionally, you can add interactive widgets for your notebook by simply inserting the YAML config in the first raw cell of the notebook.

Here is example notebook with the YAML config: notebook with YAML config

and this is the web app view generated for the notebook by Mercury: Mercury web app from notebook

You can deploy Mercury to any server because it is built on top of Django framework.

Upvotes: 0

user2320292
user2320292

Reputation: 125

A code below is a simple viewer for Jupyter notebooks. It can be used to preview quickly ipynb-files. Use the code as python jnv.py a.ipynb, where 'jnv.py' is the code below. The code can also be used in file managers, like Total Commander, if one assigns command python jnv.py as a viewer of ipynb-files.

# jnv.py: A simple viewer of a Jupyter notebooks (ipynb-files).
# Works for nbformat version >= 4.
import tkinter as tk
import sys,json

f = open(sys.argv[1], 'r',  encoding="utf8")  # input.ipynb
jf = json.load(f)
f.close()

# Take text ('source') from 'markdown' and 'code' cells
out_txt = ''
for cell in jf["cells"]:
  if cell['cell_type'] == 'markdown':
    for el in cell['source']:
      out_txt = out_txt + el
  elif  cell['cell_type'] == 'code':
    for el in cell['source']:
      out_txt = out_txt + el

# Make a frame and display 'out_txt'. Press Esc to quit.
# See https://www.python-course.eu/tkinter_text_widget.php
root = tk.Tk()

S = tk.Scrollbar(root)
T = tk.Text(root, height=24, width=80)

def select_all(event=None):
  T.tag_add('sel', '1.0', 'end')
  #return "break"
def copy_sel(event=None):
  content = T.selection_get()
  print(content)
  root.clipboard_clear()
  root.clipboard_append(content)
def key(event):
  print(event)
  if event.keycode == 27:  # pressed Esc
    root.destroy()
  elif event.char == '\x01': # Ctrl-A; make sure you use this before cursor enters text!
    select_all()
  elif event.char == '\x03': # Ctrl-C; make sure you use this before cursor enters text!
    copy_sel()

S.pack(side=tk.RIGHT, fill=tk.Y)
T.pack(side=tk.LEFT, fill=tk.Y)
S.config(command=T.yview)
T.config(yscrollcommand=S.set)

T.insert(tk.END, out_txt)
root.bind("<Key>", key)
tk.mainloop()

Upvotes: 3

Rushikesh Tade
Rushikesh Tade

Reputation: 483

Checkout this Firefox plugin. Python Notebook Viewer

Its is easy to use, Does not require you to open terminal/command prompt and can be used offline as well. Just follow steps below.

  1. Install from Firefox Addons site
  2. Drag and drop .ipynb files into firefox.
  3. alternatively you can also open notebook from menu-> file -> open file

Chrome version : Jupyter Notebook Viewer

Not the same developer but works the same way, globally.

Upvotes: 26

Ivan Drago
Ivan Drago

Reputation: 21

Pycharm professional can also view Jupyter notebooks

Upvotes: 2

piratefache
piratefache

Reputation: 1368

As you already created a notebook file, you can easily convert it to an html file. In this format it will be easy for you to share it or put it on a website. So from the prompt :

jupyter nbconvert --to html --execute YOUR_FILE.ipynb --output OUTPUT.html

There is also other format : markdown, html, pdf, ipynb, etc

Documentation here

Upvotes: 15

Related Questions