1+ import time
2+
13from chartlets import Component , Input , Output
2- from chartlets .components import Box , Typography , Table
4+ from chartlets .components import Box , Typography , Table , Skeleton , Button
35
46from server .context import Context
57from server .panel import Panel
@@ -32,11 +34,23 @@ def render_panel(
3234 ["3" , "Peter" , "Jones" , 40 ],
3335 ]
3436
35- table = Table (id = "table" , rows = rows , columns = columns , hover = True )
37+ table_skeleton = Skeleton (
38+ height = "100%" , width = "100%" , variant = "rounded" , animation = "wave" , opacity = 0.1
39+ )
40+
41+ table = Table (
42+ id = "table" ,
43+ rows = rows ,
44+ columns = columns ,
45+ hover = True ,
46+ skeletonProps = table_skeleton .to_dict (),
47+ )
3648
3749 title_text = Typography (id = "title_text" , children = ["Basic Table" ])
3850 info_text = Typography (id = "info_text" , children = ["Click on any row." ])
3951
52+ update_button = Button (id = "update_button" , text = "Update Table" )
53+
4054 return Box (
4155 style = {
4256 "display" : "flex" ,
@@ -45,14 +59,31 @@ def render_panel(
4559 "height" : "100%" ,
4660 "gap" : "6px" ,
4761 },
48- children = [title_text , table , info_text ],
62+ children = [title_text , table , update_button , info_text ],
4963 )
5064
5165
5266# noinspection PyUnusedLocal
53- @panel .callback (Input ("table" ), Output ("info_text" , "children" ))
54- def update_info_text (
55- ctx : Context ,
56- table_row : int ,
57- ) -> list [str ]:
67+ @panel .callback (
68+ Input ("table" ),
69+ Output ("info_text" , "children" ),
70+ )
71+ def update_info_text (ctx : Context , table_row : int ) -> list [str ]:
72+ time .sleep (3 )
73+
5874 return [f"The clicked row value is { table_row } ." ]
75+
76+
77+ @panel .callback (
78+ Input ("update_button" , "clicked" ),
79+ Output ("table" , "rows" ),
80+ )
81+ def update_table_rows (ctx : Context , update_button_clicked ) -> TableRow :
82+ # simulate lag to show skeleton
83+ time .sleep (3 )
84+ rows : TableRow = [
85+ ["1" , "John" , "Smith" , 94 ],
86+ ["2" , "Jane" , "Jones" , 5 ],
87+ ["3" , "Peter" , "Doe" , 40.5 ],
88+ ]
89+ return rows
0 commit comments