Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
holoviz
GitHub Repository: holoviz/panel
Path: blob/main/examples/apps/uv/app.py
3238 views
1
# /// script
2
# requires-python = ">=3.12"
3
# dependencies = [
4
# "panel",
5
# ]
6
# ///
7
import panel as pn
8
9
# Configure Panel with a modern design
10
pn.extension(design="material")
11
12
# Create interactive components
13
slider = pn.widgets.IntSlider(
14
value=5,
15
start=1,
16
end=10,
17
name="Rating"
18
)
19
20
def generate_stars(rating=5):
21
"""Convert numeric rating to star display."""
22
return "⭐" * rating
23
24
# Build the application layout
25
app = pn.Column(
26
"## ⭐ Star Rating Demo",
27
"Adjust the slider to see your rating in stars:",
28
slider,
29
pn.bind(generate_stars, slider.param.value),
30
sizing_mode="stretch_width",
31
margin=(20, 40)
32
)
33
34
# Enable dual-mode execution
35
if pn.state.served:
36
# Served mode: `panel serve script.py`
37
app.servable(title="Star Rating App")
38
elif __name__ == "__main__":
39
# Script mode: `python script.py`
40
app.show(port=5007, autoreload=True)
41
42