What is a Report?
Reports wrap the results of your Python analyses, such as datasets and plots, into interactive documents which you can share.

Introduction

For many Python data analyses, you only want to share a specific user-facing part of it rather than the whole code or notebook. This often is of the form of a standalone product that non-technical people can view directly from their existing tools - e.g. browsers, email, Slack, etc., and without the overhead and requirements of Python and Jupyter.
Datapane allows you to programmatically create reports from the objects in your Python analyses, such as pandas DataFrames, plots from visualization libraries, and Markdown text.

Creating a report

Datapane provides a Python API that allows you to create, save, and upload reports comprised of a collection of data-centric blocks.
Detailed API docs for Datapane Reports can be found at https://datapane.github.io/datapane/.
For instance, Datapane provides a Table block that takes a pandas DataFrame. We can create a Table block by passing a DataFrame into it, and create a Report with that single block in it as follows:
1
import pandas as pd
2
import datapane as dp
3
4
df = pd.read_csv('https://covid.ourworldindata.org/data/vaccinations/vaccinations-by-manufacturer.csv', parse_dates=['date'])
5
df = df.groupby(['vaccine', 'date'])['total_vaccinations'].sum().tail(1000).reset_index()
6
7
report = dp.Report(
8
dp.Table(df)
9
)
10
report.save(path='report.html', open=True)
Copied!
As seen above, Reports can be saved to local HTML files. Copying this code into a new script and running it will generate the report.
1
$ python3 simple_report.py
Copied!
If you send this HTML file to somebody (or upload it on Datapane Studio), they will be able to view your dataset, sort and filter it, and download it as a CSV.

A richer report

That report was pretty basic, but we can jazz it up by adding some plots and Markdown text. Unlike a traditional BI tool, Datapane does not rely on a proprietary visualization engine; instead, it natively supports Python visualization libraries such as Altair, Plotly, Bokeh, and Folium.
We also support an advanced Table component, called DataTable, which allows sorting, filtering, and interactive analysis - however it requires uploading your report to a Datapane server to function.
Let's take the example above, and plot some data using the Python library Altair and add some text.
We'll use the below sample code snippet for the rest of the tutorials, so feel free to copy and paste it into a new Python script or Jupyter notebook and follow along
richer_report.py
1
import pandas as pd
2
import altair as alt
3
import datapane as dp
4
5
# download data & group by manufacturer
6
df = pd.read_csv('https://covid.ourworldindata.org/data/vaccinations/vaccinations-by-manufacturer.csv', parse_dates=['date'])
7
df = df.groupby(['vaccine', 'date'])['total_vaccinations'].sum().tail(1000).reset_index()
8
9
# plot vaccinations over time using Altair
10
plot = alt.Chart(df).mark_area(opacity=0.4, stroke='black').encode(
11
x='date:T',
12
y=alt.Y('total_vaccinations:Q'),
13
color=alt.Color('vaccine:N', scale=alt.Scale(scheme='set1')),
14
tooltip='vaccine:N'
15
).interactive().properties(width='container')
16
17
# tablulate total vaccinations by manufacturer
18
total_df = df[df["date"] == df["date"].max()].sort_values("total_vaccinations", ascending=False).reset_index(drop=True)
19
total_styled = total_df.style.bar(subset=["total_vaccinations"], color='#5fba7d', vmax=total_df["total_vaccinations"].sum())
20
21
# embed into a Datapane Report
22
report = dp.Report(
23
"## Vaccination Report",
24
dp.Plot(plot, caption="Vaccinations by manufacturer over time"),
25
dp.Table(total_styled, caption="Current vaccination totals by manufacturer"),
26
dp.Table(df, caption="Initial Dataset")
27
)
28
report.save("report.html", open=True)
Copied!
When this python script is run, we get the following report.
A richer Datapane report
Next, we will explore the blocks that make up a report, followed by how to upload and optionally share reports online.
Last modified 15d ago