Tabs and Dropdowns
If you have multiple pieces of content that you don't want to show at the same time, consider using the Select block. These can be nested inside each other, and can show Tabs (5 or less options) or Dropdowns:
1
import altair as alt
2
from vega_datasets import data
3
import datapane as dp
4
import numpy as np
5
6
source = data.cars()
7
8
cylinders = np.sort(source.Cylinders.unique())
9
plots = []
10
11
# Create a list of plots
12
for c in cylinders:
13
plot = alt.Chart(source[source.Cylinders == c]).mark_circle(size=60).encode(
14
x='Horsepower',
15
y='Miles_per_Gallon',
16
tooltip=['Name', 'Horsepower', 'Miles_per_Gallon']
17
).properties(title = c.astype(str) + " Cylinders"
18
).interactive()
19
20
plots.append(plot)
21
22
report = dp.Report(
23
dp.Select(blocks = [
24
dp.Select(
25
blocks=[dp.Plot(p, label=(c.astype(str) + " Cylinders")) for p, c in zip(plots, cylinders)],
26
label = "Dropdown"),
27
dp.Select(
28
blocks=[dp.Plot(p, label=(c.astype(str) + " Cylinders")) for p, c in zip(plots, cylinders)],
29
label = "Tabs",
30
type=dp.SelectType.TABS # Override default choice
31
),
32
])
33
)
34
35
report.upload(name="Tabs and Dropdowns")
Copied!
Running that code generates the following result:
Last modified 2mo ago
Copy link