Py.Cafe

maartenbreddels/

temperature-conversion-solara

Temperature Conversion Tool

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import solara

celcius = solara.reactive(37.)

def to_farenheit(t):
    return t * 1.8 + 32

def to_celcius(t):
    return (t-32)/1.8


def set_farenheit(farenheit):
    new_value = to_celcius(farenheit)
    if abs(new_value - celcius.value) > 0.01:
        celcius.value = new_value

@solara.component
def Page():
    farenheit = to_farenheit(celcius.value)
    with solara.Card("Choose temperature"):
        solara.SliderFloat("Celcius", min=0, max=100, value=celcius)
        solara.SliderFloat("Farenheit", min=to_farenheit(0), max=to_farenheit(100), value=farenheit, on_value=set_farenheit, step=0.01)
        hot = celcius.value > 40
        if hot:
            solara.Warning("It's getting hot")

        solara.Text(repr({"celcius": celcius.value, "farenheit": farenheit}))