first app¶
create a project:
edit main.py:
import shadlet as ui
app = ui.App("counter")
@app.page("/")
def home(ctx: ui.Context):
count = ctx.state(0, key="count")
def increment(event: ui.ClickEvent):
count.value += 1
return ui.Center(
ui.Column(
ui.Heading("counter"),
ui.Text(count),
ui.Button("increment", on_click=increment),
gap=16,
),
min_height="100vh",
)
if __name__ == "__main__":
app.run()
run:
open http://127.0.0.1:8000.
what happens¶
- the python process starts a starlette server.
- the browser loads the react renderer.
- the renderer connects over websocket.
- python renders the component tree and sends it as json.
- clicks invoke the registered python callback.
- state updates patch the ui without a full reload.