Py.Cafe

b7yuvghp7/

conditional-form

Selecting Countries and Continent

DocsPricing
  • app.py
  • components.py
  • requirements.txt
  • state.py
  • utils.py
components.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import solara
# import state


continents = ["Europe", "North America", "Asia", "Australia", "Africa", "South America"]

countries = ["the Netherlands", "France", "Germany", "United States", "Canada", "Mexico" ]

@solara.component
def MyComponent(app_data):
    with solara.Card("Where do you live?"):
        # continent cannot be 2 way bound, since setting it can have effects
        solara.Select(label="Continent", value=app_data.value.continent, values=continents)
        # country can be simply 2 way bound
        solara.Select(label="Country", value=app_data.value.country, values=countries)