Skip to content

Commit 45d7761

Browse files
committed
extend demo example
1 parent 9be5d04 commit 45d7761

1 file changed

Lines changed: 34 additions & 14 deletions

File tree

chartlets.py/demo/my_extension/my_panel_8.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import altair as alt
2+
from attr.validators import disabled
23

34
from chartlets import Component, Input, State, Output
4-
from chartlets.components import (Tabs, Tab, Typography, Box,
5-
VegaChart, Table)
5+
from chartlets.components import (
6+
Tabs,
7+
Tab,
8+
Typography,
9+
Box,
10+
VegaChart,
11+
Table,
12+
IconButton,
13+
Button,
14+
)
615
from chartlets.components.table import TableColumn, TableRow
716

817
from server.context import Context
@@ -37,25 +46,31 @@ def render_panel(
3746
["3", "Peter", "Jones", 40],
3847
]
3948

49+
open_button = Button(
50+
id="open_button", startIcon="Insights", text="Please click here!"
51+
)
52+
4053
table = Table(id="table", rows=rows, columns=columns, hover=True)
4154

4255
info_text = Typography(id="info_text", children=["This is a text."])
4356
chart = VegaChart(
44-
id="chart", chart=(
45-
alt.Chart(dataset)
46-
.mark_bar()
47-
.encode(
48-
x=alt.X("x:N", title="x"),
49-
y=alt.Y("a:Q", title="a"))
50-
.properties(width=290, height=300, title="Vega charts")
51-
), style={"flexGrow": 1}
57+
id="chart",
58+
chart=(
59+
alt.Chart(dataset)
60+
.mark_bar()
61+
.encode(x=alt.X("x:N", title="x"), y=alt.Y("a:Q", title="a"))
62+
.properties(width=290, height=300, title="Vega charts")
63+
),
64+
style={"flexGrow": 1},
5265
)
5366

54-
tab1 = Tab(id = "tab1", label="Tab 1", children=[table])
55-
tab2 = Tab(id = "tab2", label="Tab 2", children=[info_text])
67+
tab1 = Tab(id="tab1", label="Tab 1", children=[table])
68+
tab2 = Tab(id="tab2", label="Tab 2", children=[info_text])
5669
tab3 = Tab(id="tab3", label="Tab 3", children=[chart])
5770

58-
tabs = Tabs(id = "tabs", value = 0, children=[tab1,tab2,tab3])
71+
tabs = Tabs(
72+
id="tabs", value=0, children=[tab1, tab2, tab3], style={"visibility": "hidden"}
73+
)
5974

6075
return Box(
6176
style={
@@ -64,6 +79,11 @@ def render_panel(
6479
"width": "100%",
6580
"height": "100%",
6681
},
67-
children=[ tabs ],
82+
children=[open_button, tabs],
6883
)
6984

85+
86+
# noinspection PyUnusedLocal
87+
@panel.callback(Input("open_button", "clicked"), Output("tabs", "style"))
88+
def tabs_on_open(ctx: Context, button) -> dict:
89+
return {"visibility": "visible"}

0 commit comments

Comments
 (0)