-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_panel_8.py
More file actions
129 lines (111 loc) · 3.03 KB
/
Copy pathmy_panel_8.py
File metadata and controls
129 lines (111 loc) · 3.03 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import altair as alt
from chartlets import Component, Input, State, Output
from chartlets.components import (
Tabs,
Tab,
Typography,
Box,
VegaChart,
Table,
Button,
)
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],
]
open_button = Button(
id="open_button", text="Show component!", style={"margin": "20px"}
)
table = Table(
id="table",
rows=rows,
columns=columns,
hover=True,
style={"width": "250px", "margin": "30px"},
)
info_text = Typography(
id="info_text", children=["This is a text."], style={"color": "pink"}
)
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, "margin": "10px"},
)
tab1 = Tab(
id="tab1",
label="Tab 1",
children=[table],
style={"backgroundColor": "darkblue", "padding": "1px"},
)
tab2 = Tab(id="tab2", label="Tab 2", children=[info_text])
tab3 = Tab(
id="tab3",
label="Tab 3",
children=[chart],
style={
"color": "darkseagreen",
"backgroundColor": "darkgreen",
"padding": "1px",
},
)
tabs = Tabs(
id="tabs",
value=0,
children=[tab1, tab2, tab3],
style={"visibility": "hidden"},
)
return Box(
style={
"display": "flex",
"flexDirection": "column",
"width": "100%",
"height": "100%",
},
children=[open_button, tabs],
)
# noinspection PyUnusedLocal
@panel.callback(
Input("open_button", "clicked"),
Input("tabs", "style"),
Output("tabs", "style"),
Output("open_button", "text"),
)
def tabs_on_open(ctx: Context, button, style) -> tuple[dict, str]:
visibility = style["visibility"]
if visibility == "hidden":
return (
{**style, "visibility": "visible"},
"Hide component!",
)
else:
return (
{**style, "visibility": "hidden"},
"Show component!",
)