Py.Cafe

iisakkirotko/

solara-switch-button-interaction

Solara Switch Button Interaction

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
import solara

@solara.component
def SwitchButton(label,value):

    def my_click_handler():
        value.set(1 - value.value)
    
    button = solara.Button(label=f"{label[value.value]}", on_click=my_click_handler)


@solara.component
def Page():
    uitaan = solara.use_reactive(0)
    linksrechts = solara.use_reactive(1)

    with solara.Row():
        SwitchButton(label=["uit","aan"],value=uitaan)
        SwitchButton(label=["links","rechts"],value=linksrechts)

    solara.Markdown(f"uitaan: {uitaan.value}")
    solara.Markdown(f"linksrechts: {linksrechts.value}")