First section

Load some packages, do some analysis, generate some plots…

import pandas as pd
import matplotlib.pyplot as plt
import os
print(os.getcwd())
## /home/sturm/projects/2019/reportsrender/tests/notebooks

Get parameters from papermill/knitr

The following setup allows to run the parametrized report with both rmarkdown and papermill:

  • We first try to get the results r.params through reticulate. (default parameters are defined in the YAML header)
  • If that fails, we use the papermill notation to define default parameters.
  • the cell needs to be tagged with parameters (see metadata)
# get default parameters. Either papermill or rmarkdown way.
try:
    input_file = r.params["input_file"]
except:
    print("Could not access params from `r` object. Don't worry if your are running papermill. ")
    input_file = "../results/01_generate_data/iris.tsv"

Second section

The following code block is shows both code and results.

# TEST: ECHO_TRUE_01
print("TEST: " + "_".join(("RESULTS", "SHOW", "01")))
## TEST: RESULTS_SHOW_01

The following code block is hidden (code and results).

Define a function to compute the fibonacci sequence.

The following code block is hidden (hide code, show results).

Show the first 10 fibonacci numbers:

## TEST: RESULTS_SHOW_02
## The 0th Fibonacci number is 0
## The 1th Fibonacci number is 1
## The 2th Fibonacci number is 1
## The 3th Fibonacci number is 2
## The 4th Fibonacci number is 3
## The 5th Fibonacci number is 5
## The 6th Fibonacci number is 8
## The 7th Fibonacci number is 13
## The 8th Fibonacci number is 21
## The 9th Fibonacci number is 34

The following code block suppresses the results:

# TEST: ECHO_TRUE_02
print("TEST: " + "_".join(("RESULTS", "HIDE")))
for i in range(10):
    print("The {i}th Fibonacci number is {f}".format(i=i, f=fib(i)))
plt.plot(range(10), [fib(x) for x in range(10)])

Summary

Every notebook should hava summary section that’s understandable by biologists. Include the ‘highlights’ here and repeat the corresponding figures.

##      Sepal.Length  Sepal.Width  Petal.Length  Petal.Width    Species
## 0             5.1          3.5           1.4          0.2     setosa
## 1             4.9          3.0           1.4          0.2     setosa
## 2             4.7          3.2           1.3          0.2     setosa
## 3             4.6          3.1           1.5          0.2     setosa
## 4             5.0          3.6           1.4          0.2     setosa
## ..            ...          ...           ...          ...        ...
## 145           6.7          3.0           5.2          2.3  virginica
## 146           6.3          2.5           5.0          1.9  virginica
## 147           6.5          3.0           5.2          2.0  virginica
## 148           6.2          3.4           5.4          2.3  virginica
## 149           5.9          3.0           5.1          1.8  virginica
## 
## [150 rows x 5 columns]

… And here is a cat skull included from the resource dir. Pandoc should include it in the HTML

cat skull