Spaces:
Sleeping
Sleeping
Create sol.py
Browse files
sol.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import solara
|
2 |
+
|
3 |
+
# Declare reactive variables at the top level. Components using these variables
|
4 |
+
# will be re-executed when their values change.
|
5 |
+
sentence = solara.reactive("Solara permite implementar rapido un frontend reactivo.")
|
6 |
+
word_limit = solara.reactive(10)
|
7 |
+
|
8 |
+
@solara.component
|
9 |
+
def Page():
|
10 |
+
# Calculate word_count within the component to ensure re-execution when reactive variables change.
|
11 |
+
word_count = len(sentence.value.split())
|
12 |
+
|
13 |
+
solara.SliderInt("Word limit", value=word_limit, min=2, max=20)
|
14 |
+
solara.InputText(label="Your sentence", value=sentence, continuous_update=True)
|
15 |
+
|
16 |
+
# Display messages based on the current word count and word limit.
|
17 |
+
if word_count >= int(word_limit.value):
|
18 |
+
solara.Error(f"With {word_count} words, you passed the word limit of {word_limit.value}.")
|
19 |
+
elif word_count >= int(0.8 * word_limit.value):
|
20 |
+
solara.Warning(f"With {word_count} words, you are close to the word limit of {word_limit.value}.")
|
21 |
+
else:
|
22 |
+
solara.Success("Great short writing!")
|
23 |
+
|
24 |
+
|
25 |
+
# The following line is required only when running the code in a Jupyter notebook:
|
26 |
+
Page()
|