Jupyter notebooks

From GHER

Jump to: navigation, search

Contents

General

Jupyter notebooks are open-source web applications that allows you to create and share documents that contain

  • live code,
  • equations,
  • visualizations and
  • explanatory text.

A similar tool is beaker, which allows user to have different languages inside the same document.
Let's keep an eye on it!

Installation

Prerequisite

Python has to be installed on the machine.

Procedure

  • Easy way: use Anaconda
  • Other way: pip tool:
pip3 install --upgrade pip
pip3 install jupyter

Add new Kernels

  1. Install python3
  2. Install jupyter using pip:
sudo -H pip3.6 install jupyter

where the flag -H requests that the security policy set the HOME environment variable to the home directory specified by the target user's password database entry. If you don't have sudo privileges:

pip install --user jupyter 

Bash

pip install bash_kernel
python -m bash_kernel.install

Julia

In julia, type:

julia> Pkg.add("IJulia")

then open a notebook:

jupyter-notebook

and select the Julia Kernel.

R

In R (assumed it's already installed):

install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
IRkernel::installspec()

It works.

Source: https://irkernel.github.io/installation/

Python with virtualenv

Use the following commands with the obvious substitutions of env_name and Display_name:

workon env_name
pip install ipykernel
python -m ipykernel install --user --name env_name --display-name "Display_name"

then restart jupyter-notebook. The new Kernel should be visible in the list.
Source: http://stackoverflow.com/questions/37891550/jupyter-notebook-running-kernel-in-different-env

Export notebooks

Can be exported in various formats directly from the environment.

Generate presentation

Output: HTML slideshow


  • In View | Cell toolbar, select Slideshow (see image below)

  • For each cell of the notebook, select the desired type

  • In a terminal, type
ipython nbconvert your_slides.ipynb --to slides --post serve

Source: http://www.damian.oquanta.info/posts/make-your-slides-with-ipython.html

Configuration

Plots

Usually matplotlib reads a file called matplotlibrc to know the parameters for the plot (see http://matplotlib.org/users/customizing.html for details).
However, when one uses a notebook, there is also a file inside ipykernel/pylab/config.py that overrides the initial values for some of the parameters when the command

%matplotlib 

is issued.

Note that such a config.py file exists for each kernel and virtual environment. For example:

/usr/local/lib/python3.6/site-packages/ipykernel/pylab/config.py
${HOME}/.julia/v0.5/Conda/deps/usr/pkgs/ipykernel-4.5.2-py27_0/lib/python2.7/site-packages/ipykernel/pylab/config.py
${HOME}/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/ipykernel/pylab/config.py

Source: http://stackoverflow.com/questions/42656668/matplotlibrc-rcparams-modified-for-jupyter-inline-plots

Stuff to test

  • Customize style (GHER theme for example):

https://github.com/dunovank/jupyter-themes
http://sherifsoliman.com/2016/01/11/theming-ipython-jupyter-notebook/

Personal tools