Skip to content

Commit 016f515

Browse files
committed
update demo to add lag to show skeleton
1 parent 4d34fb4 commit 016f515

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

chartlets.py/demo/my_extension/my_panel_1.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from typing import Any
23
import altair as alt
34
from chartlets import Component, Input, Output, State
@@ -13,7 +14,9 @@
1314
@panel.layout()
1415
def render_panel(ctx: Context) -> Component:
1516
selected_dataset: int = 0
16-
chart_skeleton = Skeleton(height="100px", variant="rounded", animation="wave")
17+
chart_skeleton = Skeleton(
18+
height="100%", width="100%", variant="rounded", animation="wave", opacity=0.1
19+
)
1720
chart = VegaChart(
1821
id="chart",
1922
chart=make_chart(ctx, selected_dataset),
@@ -56,6 +59,8 @@ def render_panel(ctx: Context) -> Component:
5659
def make_chart(ctx: Context, selected_dataset: int = 0) -> alt.Chart:
5760
dataset_key = tuple(ctx.datasets.keys())[selected_dataset]
5861
dataset = ctx.datasets[dataset_key]
62+
# simulate lag to show skeleton
63+
time.sleep(5)
5964

6065
variable_name = "a" if selected_dataset == 0 else "u"
6166

@@ -107,6 +112,8 @@ def get_click_event_points(
107112
that was clicked.
108113
109114
"""
115+
# simulate lag to show skeleton
116+
time.sleep(5)
110117
if points:
111118
conditions = []
112119
for field, values in points.items():

chartlets.py/demo/my_extension/my_panel_6.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import time
2+
13
from chartlets import Component, Input, Output
2-
from chartlets.components import Box, Typography, Table
4+
from chartlets.components import Box, Typography, Table, Skeleton, Button
35

46
from server.context import Context
57
from 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

Comments
 (0)