Py.Cafe

paddymul/

solara-json-selector

Interactive JSON Selector

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# check out https://solara.dev/ for documentation
# or https://github.com/widgetti/solara/
# And check out https://py.cafe/maartenbreddels for more examples
import solara

# reactive variables will trigger a component rerender
# when changed.
# When you change the default (now 0), hit the embedded browser
# refresh button to reset the state
clicks = solara.reactive(0)


foods = ["Kiwi", "Banana", "Apple"]
food = solara.reactive("Banana")

code_snippets = {
    "Kiwi": '''
    {"foo": 8, "bar": 9}
    ''',
    "Apple": '''
    {"boop": 10, "bar": 10}
    ''',
}


@solara.component
def Page():
    print("The component render function gets called")
    # change this code, and see the output refresh

    solara.Select(label="Food", value=food, values=foods)

    json_code = f"""
```python
{code_snippets[food.value]}
```"""
    solara.Markdown(f"**Selected**: {food.value}")
    solara.Markdown(f"**Selected**: {food.value}")


# Solara also supports ipywidgets
# remove the Page component and assign an ipywidget to
# the page variable, e.g.
# page = mywidget