Interactive Notebooks for Python, Julia, and R
April 6, 2024
Developed in 2014.
It’s name is a reference to the three core programming languages it supports:
Today now supports many more languages (SQL, Ruby, …).
Jupyter Notebooks
JupyterLab
JupyterHub
Requires:
pip install jupyter
To use in VS Code, you need the “Jupyter” extension.
I recommend setting up a “.venv” environment before installing jupyter.
In VS Code,
pip install jupyter
in the terminalJupyter notebooks have a unique extension: “.ipynb”
Simply create an empty file with that extension and VS Code will recognize it as a Jupyter notebook.
Jupyter Notebooks execute code by sending it to one of many possible “kernels”.
You can choose as your kernel:
Using a language as a kernel requies some setup for each language.
Python can be used as a Kernel once the jupyter
package is installed.
I recommend using your python environment “.venv” as your kernel.
To use Julia as a kernel, you first need to install
IJulia
packageHere it is probably easiest to just install Ijulia
system-wide
To use R as a kernel, you first need to install
IRkernel
packageHere it is probably easiest to just install IRkernel
system-wide.
You should also run the followin in R to finish the setup: IRkernel::installspec()
Whenever you open a Jupyter Notebook you will be able to choose the kernel you want to use.
Jupyter notebooks have two types of cells:
Markdown cells allow you to write and render markdown.
You can actually do this without any kernel attached.
All of the usual markdown formatting is allowed (headers, links, bullets, etc.)
Code cells are where you write code.
Each code cell can be execute individually.
Output, errors, and warnings are displayed after the individual code cell.
.ipynb
filesThe “interactive python notebook” files are actually just JSON files.
JSON is a common file format.
You can always open up a Jupyter notebook with a basic text editor.
A key feature of Jupyter notebooks is
This means
Two options for editing Jupyter Notebooks:
in the browser
in VS Code
This is the default built in to the jupyter
package.
In your workspace run:
This will launch a http server in the terminal.
And it will open a window in your browser with the editor.
Once you have installed the Jupyter VS Code extension
Behind the scenes, VS Code will launch the kernel as a http server, send the code to it, bring back the results.
Both have code and markdown “chunks” (cells).
Jupyter Notebooks
Quarto
Quarto can compile a Jupyter notebook into any of is output formats.
This allows you to quickly turn your Jupyter Notebooks into pdf reports, or website pages, etc.
Instead, you can use Jupyter as the engine for Quarto (instead of R).
You can also switch to using the Julia kernel for Jupyter.
rmarkdown
RPluto.jl
JuliaQuarto
Julia, Python, RJupyter Notebooks
Julia, Python, RJupyter’s big difference: output is included in the notebook file.
I love to use Quarto (and before that rmarkdown).
But I think your research project should not be in a notebook.