-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_panel_8.py
More file actions
69 lines (55 loc) · 1.91 KB
/
Copy pathmy_panel_8.py
File metadata and controls
69 lines (55 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import altair as alt
from chartlets import Component, Input, State, Output
from chartlets.components import (Tabs, Tab, Typography, Box,
VegaChart, Table)
from chartlets.components.table import TableColumn, TableRow
from server.context import Context
from server.panel import Panel
panel = Panel(__name__, title="Panel H")
@panel.layout(State("@app", "selectedDatasetId"))
def render_panel(
ctx: Context,
selected_dataset_id: str = "",
) -> Component:
dataset = ctx.datasets.get(selected_dataset_id)
columns: list[TableColumn] = [
{"id": "id", "label": "ID", "sortDirection": "desc"},
{
"id": "firstName",
"label": "First Name",
"align": "left",
"sortDirection": "desc",
},
{"id": "lastName", "label": "Last Name", "align": "center"},
{"id": "age", "label": "Age"},
]
rows: TableRow = [
["1", "John", "Doe", 30],
["2", "Jane", "Smith", 25],
["3", "Peter", "Jones", 40],
]
table = Table(id="table", rows=rows, columns=columns, hover=True)
info_text = Typography(id="info_text", children=["This is a text."])
chart = VegaChart(
id="chart", chart=(
alt.Chart(dataset)
.mark_bar()
.encode(
x=alt.X("x:N", title="x"),
y=alt.Y("a:Q", title="a"))
.properties(width=290, height=300, title="Vega charts")
), style={"flexGrow": 1}
)
tab1 = Tab(id = "tab1", label="Tab 1", children=[table])
tab2 = Tab(id = "tab2", label="Tab 2", children=[info_text])
tab3 = Tab(id="tab3", label="Tab 3", children=[chart])
tabs = Tabs(id = "tabs", value = 0, children=[tab1,tab2,tab3])
return Box(
style={
"display": "flex",
"flexDirection": "column",
"width": "100%",
"height": "100%",
},
children=[ tabs ],
)