55import altair as alt
66
77from chartlets import Component , Input , State , Output
8- from chartlets .components import (Tabs , Tab , Typography , Box ,
9- VegaChart , Table )
8+ from chartlets .components import (
9+ Tabs ,
10+ Tab ,
11+ Typography ,
12+ Box ,
13+ VegaChart ,
14+ Table ,
15+ Button ,
16+ )
1017from chartlets .components .table import TableColumn , TableRow
1118
1219from server .context import Context
@@ -41,25 +48,48 @@ def render_panel(
4148 ["3" , "Peter" , "Jones" , 40 ],
4249 ]
4350
44- table = Table (id = "table" , rows = rows , columns = columns , hover = True )
51+ open_button = Button (
52+ id = "open_button" , text = "Show component!" , style = {"margin" : "20px" }
53+ )
54+
55+ table = Table (
56+ id = "table" ,
57+ rows = rows ,
58+ columns = columns ,
59+ hover = True ,
60+ style = {"width" : "100%" , "padding" : "2px" },
61+ )
4562
46- info_text = Typography (id = "info_text" , children = ["This is a text." ])
4763 chart = VegaChart (
48- id = "chart" , chart = (
49- alt . Chart ( dataset )
50- . mark_bar ( )
51- . encode (
52- x = alt .X ("x:N" , title = "x" ),
53- y = alt . Y ( "a:Q" , title = "a" ) )
54- . properties ( width = 290 , height = 300 , title = "Vega charts" )
55- ), style = {"flexGrow" : 1 }
64+ id = "chart" ,
65+ chart = (
66+ alt . Chart ( dataset )
67+ . mark_bar ()
68+ . encode ( x = alt .X ("x:N" , title = "x" ), y = alt . Y ( "a:Q" , title = "a" ))
69+ . properties ( width = 290 , height = 300 , title = "Vega charts" )
70+ ),
71+ style = {"flexGrow" : 1 , "margin" : "10px" },
5672 )
5773
58- tab1 = Tab (id = "tab1" , label = "Tab 1" , children = [table ])
59- tab2 = Tab (id = "tab2" , label = "Tab 2" , children = [info_text ])
60- tab3 = Tab (id = "tab3" , label = "Tab 3" , children = [chart ])
74+ tab1 = Tab (
75+ id = "tab1" ,
76+ label = "Tab 1" ,
77+ children = [table ],
78+ style = {"backgroundColor" : "darkblue" , "padding" : "1px" },
79+ )
80+ tab2 = Tab (id = "tab2" , label = "Tab 2" , children = ["This is a text." ], disabled = True )
81+ tab3 = Tab (
82+ id = "tab3" ,
83+ label = "Tab 3" ,
84+ children = [chart ],
85+ )
6186
62- tabs = Tabs (id = "tabs" , value = 0 , children = [tab1 ,tab2 ,tab3 ])
87+ tabs = Tabs (
88+ id = "tabs" ,
89+ value = 0 ,
90+ children = [tab1 , tab2 , tab3 ],
91+ style = {"visibility" : "hidden" },
92+ )
6393
6494 return Box (
6595 style = {
@@ -68,6 +98,27 @@ def render_panel(
6898 "width" : "100%" ,
6999 "height" : "100%" ,
70100 },
71- children = [ tabs ],
101+ children = [open_button , tabs ],
72102 )
73103
104+
105+ # noinspection PyUnusedLocal
106+ @panel .callback (
107+ Input ("open_button" , "clicked" ),
108+ Input ("tabs" , "style" ),
109+ Output ("tabs" , "style" ),
110+ Output ("open_button" , "text" ),
111+ )
112+ def tabs_on_open (ctx : Context , button , style ) -> tuple [dict , str ]:
113+ visibility = style ["visibility" ]
114+
115+ if visibility == "hidden" :
116+ return (
117+ {** style , "visibility" : "visible" },
118+ "Hide component!" ,
119+ )
120+ else :
121+ return (
122+ {** style , "visibility" : "hidden" },
123+ "Show component!" ,
124+ )
0 commit comments