Skip to article frontmatterSkip to article content

Example Jupyter Notebook

Here are some basic elements of a Jupyter Notebook and how they render via JupyterBook to create this site.

To make nice headers, use standard markdown # syntax, where

# Heading 1
## Heading 2
### Heading 3
#### etc...

becomes

Heading 1

Heading 2

Heading 3

Heading 4

Regular text can be made bold with double-asterisks

**bunch of bold text**

becomes bunch of bold text

And the same is true for using an underscore for italics

_suggestive italics text_

becomes suggestive italics text

Use - to make unordered (bulleted) lists

- item
- another item
- yet another item

becomes

  • item
  • another item
  • yet another item

Create hyperlinks from text using:

[hyperlinks](https://www.youtube.com)

Add an exclamation point to the beginning and you’re embedding an image (can be local or url)

Look at this ![alt_text of image](https://wallpapers.com/images/hd/elephant-background-kl16hvsjxq9g1rs5.jpg)

Look at this alt_text of image

Use 1. to make ordered (numbered) lists

1. eggs
2. avocado
3. rye toast

becomes

  1. eggs
  2. avocado
  3. rye toast

MyST-specific perks

Jupyterbook uses an extension of Markdown called MyST that is more feature-rich than standard markdown. We won’t highlight them all here, but there is a great cheat sheet.

You can create fun/useful admonitions to give important heads-ups.

:::{tip}
Try changing `tip` to `warning`!
:::

becomes

Code and execution

Where Jupyter Notebooks shine is that code cells can be executed, and the notebook captures the output of the cell, storing the output into the notebook. So, grab your favorite langauge kernel (Python, R, Julia, bash, whatever), which may require separate installation, and run the code you need.

Bash

We use bash a lot of time, and Jupyter has a series of “magics” that are a short magic term that goes at the top of a code cell and modifies how it runs. One of the most useful for bioinformatics is the %%shell magic. Add that to the top of a code cell and Jupyter will execute it as shell code. Example:

%%shell

for i in {1..10}; do
  touch file.${i}.txt
done

R code

You’re probably going to use R a bunch. For that you’ll need IRKernel. Installation is pretty simple. This will let you load the R kernel in Jupyter and execute R code, once again letting Jupyter capture the output in the cells. Below are some examples.

max(rnorm(50))
Loading...
plot(x = runif(30), y = rnorm(30), pch = 19, col = "indianred")
plot without title