Dashboard with rows and columns
The Group block is a great way to create grid layouts - just specify the number of rows and columns you want. You can also nest groups within each other. If you have a non-fixed number of plots, you can pass them in as a list via the blocks parameter:
1
import altair as alt
2
from vega_datasets import data
3
import datapane as dp
4
5
source = data.cars()
6
7
origins = source.Origin.unique()
8
plots = []
9
10
# Create a list of plots
11
for o in origins:
12
plot = alt.Chart(source[source.Origin == o]).mark_circle(size=60).encode(
13
x='Horsepower',
14
y='Miles_per_Gallon',
15
tooltip=['Name', 'Horsepower', 'Miles_per_Gallon']
16
).properties(title=o
17
).interactive()
18
19
plots.append(plot)
20
21
report = dp.Report(
22
dp.Group(
23
dp.Text("![](https://images.unsplash.com/photo-1551288049-bebda4e38f71?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1470&q=80)"),
24
dp.Group(
25
dp.BigNumber(
26
heading="Total datapoints",
27
value=source.Name.count(),
28
),
29
dp.BigNumber(
30
heading="Average miles per gallon",
31
value=round(source.Miles_per_Gallon.mean(), 2)
32
),
33
rows=2
34
), columns = 2
35
),
36
dp.Group(
37
blocks = plots,
38
columns = len(plots),
39
)
40
)
41
42
report.upload(name="Dashboard layout")
Copied!
Running this code generates the following report:
Last modified 2mo ago
Copy link