jupyter | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Generating HTML/PDF reports.
Ploomber makes it simple to generate HTML and PDF reports from notebooks and scripts. To see some examples, go to the reports/
directory. This cookbook covers several use cases and includes runnable examples.
HTML reports are the simplest option as they don't require any extra dependencies. You only need to change the product
extension to .html
and Ploomber will do the conversion:
<% expand('pipeline.yaml', lines=(2, 7)) %>
Runnable example:
# get example
pip install ploomber "nbconvert[webpdf]" --upgrade
ploomber examples -n cookbook/report-generation -o example
cd example
# install example dependencies
ploomber install
# generate HTML report
ploomber task html-report
Check out report at reports/report.html
To generate PDF reports there are two options, using chromium or TeX.
To use use chromium, pass nbconvert_exporter_name: webpdf
<% expand('pipeline.yaml', lines=(26, 33)) %>
Runnable example:
# get example
pip install ploomber "nbconvert[webpdf]" --upgrade
ploomber examples -n cookbook/report-generation -o example
cd example
# install example dependencies
ploomber install
# generate PDF report
ploomber task webpdf-report
Check out report at reports/report-webpdf.pdf
TeX is the default, to use it, set the product extension to .pdf
:
<% expand('pipeline.yaml', lines=(35, 40)) %>
Runnable example:
# get example
pip install ploomber "nbconvert[webpdf]" --upgrade
ploomber examples -n cookbook/report-generation -o example
cd example
# install example dependencies
ploomber install
# generate PDF report
ploomber task pdf-report
Check out report at reports/report.pdf
For instructions on installing TeX, see this..
TeXLive is a large distribution, as an alternative, you may install BasicTeX. Here are instructions for macOS.
Upon BasicTeX installation, you'll need to install a few extra packages:
# Note: if using macOS or Linux, you may need to execute with sudo
tlmgr install adjustbox \
caption \
collectbox \
enumitem \
environ \
eurosym \
jknapltx \
parskip \
pgf \
rsfs \
tcolorbox \
titling \
trimspaces \
ucs \
ulem \
upquote
In many cases, you want to hide the code so the report only contains tables and charts, you can do so easily with the exclude_input
option:
<% expand('pipeline.yaml', lines=(9, 17)) %>
Runnable example:
# get example
pip install ploomber "nbconvert[webpdf]" --upgrade
ploomber examples -n cookbook/report-generation -o example
cd example
# install example dependencies
ploomber install
# generate HTML report and hide code
ploomber task another-html-report
Check out report at reports/another.html
You may want to hide cells from the output notebook selectively. You can do so with the TagRemovePreprocessor
, which takes a list of tags. Any cells with such tags are excluded:
<% expand('pipeline.yaml', lines=(9, 24)) %>
To learn how to add cell tags, see this.
Runnable example:
# get example
pip install ploomber "nbconvert[webpdf]" --upgrade
ploomber examples -n cookbook/report-generation -o example
cd example
# install example dependencies
ploomber install
# generate HTML report and hide boxplot
ploomber task another-html-report
Check out report at reports/another.html