Py.Cafe

iisakkirotko/

solara-fetch-data

Fetch Data Insights

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
import asyncio
import solara
from solara.lab import task

@task
async def fetch_data():
    await asyncio.sleep(2)
    return "The answer is 42"

@solara.component
def Page():
    solara.Button("Fetch data", on_click=fetch_data)
    solara.ProgressLinear(fetch_data.pending)

    if fetch_data.finished:
        solara.Text(fetch_data.value)
    elif fetch_data.not_called:
        solara.Text("Click the button to fetch data")
    # Optional state check
    # elif fetch_data.cancelled:
    #     solara.Text("Cancelled the fetch")
    # elif fetch_data.error:
    #     solara.Error(str(fetch_data.exception))