'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.
I appreciate your help.
Thanks, J.
Solution 1:[1]
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:
- Jupyter Notebooks IPYNB Viewer: chrome extension to view/convert nbs
- 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
Solution 2:[2]
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.
- Install from Firefox Addons site
- Drag and drop .ipynb files into firefox.
- 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.
Solution 3:[3]
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
Solution 4:[4]
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()
Solution 5:[5]
Pycharm professional can also view Jupyter notebooks
Solution 6:[6]
If you want to share your Juptyer / IPython notebooks online, try using jovian.ml . It's a platform for sharing on collaborating on Jupyter notebooks, and it's really easy to use.
Step 1: Install the Jovian python library
pip install jovian
Step 2: Import the library inside your Jupyter / IPython notebook
import jovian
Step 3: Upload the notebook to your Jovian account by running
jovian.commit()
inside the Jupyter notebook. This will capture the Juptyer notebook (and also the Python libraries required to run it), and upload it your account, giving you shareable link. Here's an example: https://www.jovian.ml/aakashns/01-pytorch-basics
Viewers can also run your notebook on cloud platforms like Google Colab, BinderHub and Kaggle with a single click.
Solution 7:[7]
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:
and this is the web app view generated for the notebook by Mercury:
You can deploy Mercury to any server because it is built on top of Django framework.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Richie Cotton |
Solution 2 | Mehdi LAMRANI |
Solution 3 | piratefache |
Solution 4 | sdbbs |
Solution 5 | Ivan Drago |
Solution 6 | aakashns |
Solution 7 | pplonski |