Stat
A dashboard tile: a title, a large value, an optional change (delta, shown as +4.2% in green or red) and an optional trend drawn as a sparkline.
ui.stat · Category: Data · Full reference →


pz.row([ ui.stat("Users", "1,284", delta=12.5, trend=[3, 5, 4, 6, 8, 7, 9], width=200), ui.stat("Errors", "37", delta=-8.0, width=200), ui.stat("Build time", "1m 12s", width=200),], spacing=12)When to use
Section titled “When to use”- For key numbers at the top of a dashboard or report.
import pyzed as pzfrom pyzed import ui
pz.row([ ui.stat("Users", "1,284", delta=12.5, trend=[3, 5, 4, 6, 8, 7, 9], width=200), ui.stat("Errors", "37", delta=-8.0, width=200), ui.stat("Build time", "1m 12s", width=200),], spacing=12)Variants
Section titled “Variants”Content
Section titled “Content”

Code
ui.stat("Build time", "1m 12s", width=190)

delta=12.5Code
ui.stat("Users", "1,284", delta=12.5, width=190)

delta=-8.0Code
ui.stat("Errors", "37", delta=-8.0, width=190)![Stat: trend=[...]](/pyzed/library/stat-v1-4.dark.webp)
![Stat: trend=[...]](/pyzed/library/stat-v1-4.light.webp)
trend=[...]Code
ui.stat("Revenue", "$9.4k", delta=4.2, trend=[3, 5, 4, 6, 8, 7, 9], width=190)States and events
Section titled “States and events”With inverse=True a drop is good news (green), for errors or latency.


icon=, inverse=TrueCode
ui.stat("Errors", "12", delta=-8.0, inverse=True, icon="bug", width=180)

on_press=Code
ui.stat("Users", "1,204", delta=4.2, icon="users", on_press=on_press, width=180)Events
Section titled “Events”Stat has 1 event of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.
| Event | Handler gets | When |
|---|---|---|
on_press |
() |
Makes the card clickable. |
Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().
Handling the events
Section titled “Handling the events”The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.
class Dashboard(pz.App): def __init__(self): self.detail = None
def view(self): return pz.column([ pz.row([ui.stat("Users", "1,284", delta=12.5, width=200, on_press=lambda: setattr(self, "detail", "Users")), # the whole card ui.stat("Errors", "37", delta=-8.0, width=200, on_press=lambda: setattr(self, "detail", "Errors"))], spacing=12), ui.muted(f"Details of {self.detail}" if self.detail else "Click a number"), ], spacing=8)from dataclasses import dataclass
@dataclassclass Open: metric: str
class Dashboard(pz.App): detail = None
def update(self, message): match message: case Open(metric): self.detail = metric
def view(self): return pz.row([ui.stat(m, v, width=200, on_press=Open(m)) for m, v in (("Users", "1,284"), ("Errors", "37"))], spacing=12)from dataclasses import dataclass
@dataclass(frozen=True)class State: detail: str = ""
def view(state, set_state): return pz.row([ui.stat(m, v, width=200, on_press=lambda m=m: set_state(detail=m)) for m, v in (("Users", "1,284"), ("Errors", "37"))], spacing=12)Properties and API
Section titled “Properties and API”ui.stat
Section titled “ui.stat”stat( title, value, *, delta=None, trend=None, width=None, icon=None, inverse=False, on_press=None, theme=None,)A dashboard number: title, large value, optional change (+4.2%) and sparkline.
| Property | Default | Description |
|---|---|---|
title |
required | Title. |
value |
required | Current value. |
delta |
None |
Change in %; green if positive, red otherwise. |
trend |
None |
Values for the sparkline. |
width |
None |
Width: pixels, "fill", "shrink" or "fill:N" (proportion). |
icon |
None |
Icon before the title. |
inverse |
False |
Colors a drop green and a rise red (errors, latency…). |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
Events: on_press (events).