Skip to content

Commit c4bea32

Browse files
committed
add demo
1 parent 86bee36 commit c4bea32

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

chartlets.py/demo/my_extension/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
from .my_panel_2 import panel as my_panel_2
44
from .my_panel_3 import panel as my_panel_3
55
from .my_panel_4 import panel as my_panel_4
6+
from .my_panel_6 import panel as my_panel_6
67

78
ext = Extension(__name__)
89
ext.add(my_panel_1)
910
ext.add(my_panel_2)
1011
ext.add(my_panel_3)
1112
ext.add(my_panel_4)
13+
ext.add(my_panel_6)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from chartlets import Component, Input, State, Output
2+
from chartlets.components import Box, Typography, Table
3+
4+
from server.context import Context
5+
from server.panel import Panel
6+
7+
from chartlets.components.table import TableColumn, TableRowData
8+
9+
panel = Panel(__name__, title="Panel F")
10+
11+
12+
# noinspection PyUnusedLocal
13+
@panel.layout()
14+
def render_panel(
15+
ctx: Context,
16+
) -> Component:
17+
columns: list[TableColumn] = [
18+
{"id": "id", "label": "ID"},
19+
{"id": "firstName", "label": "First Name", "align": "left"},
20+
{"id": "lastName", "label": "Last Name", "align": "center"},
21+
{"id": "age", "label": "Age"},
22+
]
23+
24+
rows: list[TableRowData] = [
25+
{
26+
"id": 1,
27+
"data": {"id": "1", "firstName": "John", "lastName": "Doe", "age": 30},
28+
},
29+
{
30+
"id": 2,
31+
"data": {"id": "2", "firstName": "Jane", "lastName": "Smith", "age": 25},
32+
},
33+
{
34+
"id": 3,
35+
"data": {"id": "3", "firstName": "Peter", "lastName": "Jones", "age": 40},
36+
},
37+
]
38+
39+
table = Table(id="table", rows=rows, columns=columns, hover=True)
40+
41+
title_text = Typography(id="title_text", children=["Basic Table"])
42+
info_text = Typography(id="info_text", children=["Click on any row."])
43+
44+
return Box(
45+
style={
46+
"display": "flex",
47+
"flexDirection": "column",
48+
"width": "100%",
49+
"height": "100%",
50+
"gap": "6px",
51+
},
52+
children=[title_text, table, info_text],
53+
)
54+
55+
56+
# noinspection PyUnusedLocal
57+
@panel.callback(Input("table"), Output("info_text", "children"))
58+
def update_info_text(
59+
ctx: Context,
60+
table_row: int,
61+
) -> list[str]:
62+
return [f"The clicked row value is {table_row}."]

0 commit comments

Comments
 (0)