Skip to content

Commit 700819e

Browse files
committed
Add py test
1 parent 901ca05 commit 700819e

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

chartlets.py/chartlets/components/slider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Slider(Component):
7979
`false`: the track will render without a bar.
8080
"""
8181

82-
value: bool | None = None
82+
value: list[int] | int | None = None
8383
"""The value of the slider. For ranged sliders, provide an array with two
8484
values.
8585
"""
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from chartlets import Component, Input, State, Output
2+
from chartlets.components import Box, Slider, Typography
3+
4+
from server.context import Context
5+
from server.panel import Panel
6+
7+
8+
panel = Panel(__name__, title="Panel D")
9+
10+
11+
@panel.layout()
12+
def render_panel(
13+
ctx: Context,
14+
) -> Component:
15+
marks = [
16+
{
17+
"value": 0,
18+
"label": "0",
19+
},
20+
{
21+
"value": 20,
22+
"label": "20",
23+
},
24+
{
25+
"value": 37,
26+
"label": "37",
27+
},
28+
{
29+
"value": 100,
30+
"label": "100",
31+
},
32+
]
33+
slider = Slider(
34+
id="slider", min=0, max=100, step=5, marks=marks, valueLabelDisplay="auto"
35+
)
36+
37+
info_text = Typography(id="info_text", children=["Move the slider."])
38+
39+
return Box(
40+
style={
41+
"display": "flex",
42+
"flexDirection": "column",
43+
"width": "100%",
44+
"height": "100%",
45+
"gap": "6px",
46+
},
47+
children=[slider, info_text],
48+
)
49+
50+
51+
# noinspection PyUnusedLocal
52+
@panel.callback(Input("slider"), Output("info_text", "children"))
53+
def update_info_text(
54+
ctx: Context,
55+
slider: int,
56+
) -> list[str]:
57+
slider = slider or 0
58+
return [f"The value is {slider}."]

0 commit comments

Comments
 (0)