Skip to main content

Generate static reports from Jupyter notebooks

Project description

leda

Generate static reports with interactive widgets from Jupyter notebooks

PyPI version PyPI Supported Python Versions GitHub Actions (Tests)

Quick Start

Generate a static HTML report from a Jupyter notebook:

python -m leda /path/to/nb.ipynb --output-dir ./outputs/

# Optional args:
python -m leda /path/to/nb.ipynb --output-dir ./outputs/ \
    -i "abc = 123" -k "other_kernel" --cell-timeout 100

This will automatically include formatting tweaks, including, e.g., hiding all input code.

-i (--inject) is used to inject user code via a new cell prepended to the notebook during generation.

Think of it like voila or nbviewer but with widgets.

Note: leda assumes that all code is run in a trusted environment, so please be careful.

Interaction/Widgets

leda provides an %%interact magic that makes it easy to create outputs based on widgets, like:

%%interact mult0=[1,2,3],mult1=[10,100,1000]
df = pd.DataFrame({"a": [1, 2, 3]}) * mult0 * mult1
df.plot(title=f"Foo: {mult0}, {mult1}")

There are two types of interact modes: dynamic and static. Dynamic mode is when you're running the Jupyter notebook live, in which case you will re-compute the cell output every time you select a different mult.

In a static mode (using whichever static widget backend is configured), the library will pre-compute all possible combinations of widget states (see Cartesian product) and then render a static HTML report that contains widgets that look and feel like the dynamic widgets (despite being pre-rendered).

Report Web UI Server

Unlike voila, because all report output is static HTML, you can stand up a report web UI server that suits your needs very easily. That means:

  • It's trivial to set up in many cases.
  • It's as scalable as your web server.
  • It's more cost-efficient because there are no runtimes whatsoever.
  • You don't have to worry about old versions no longer working due to code or data changes, so the historical archive of old reports never expire or change or break.

For example, you can generate the report to a file, upload that file to a shared location, and then stand up a bare-bones nginx server to serve the files. (Instead of having a two-step of generation + upload, you could alternatively implement your own leda.gen.base.ReportPublisher and create a generation script of your own).

Params

Reports can be parametrized so that the user can set different values for each report run.

In the notebook, just use leda.get_param():

data_id = leda.get_param("data_id", dynamic_default=1, static_default=2)

And then change the injected code during each run:

python -m leda /path/to/nb.ipynb --output ./outputs/ -i "data_id = 100"

Modular

leda is built to work with multiple visualization and widget libraries.

Works with these visualization libraries:

With the default dynamic widget library:

And with these static widget libraries:

Testing

See the requirements-bundle*.txt for version bundles that we currently test manually.

he most important next task for leda development would be to (1) automate testing generating reports (reports may contain many random strs that don't affect the output but make it impossible to do a simple diff), and (2) expand the number of bundles being tested (especially to the newer versions).

(All of these bundles will be tested against Linux/macOS/Windows and various python versions.)

Known Issues

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leda-0.3.0.tar.gz (304.0 kB view hashes)

Uploaded Source

Built Distribution

leda-0.3.0-py3-none-any.whl (30.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page