Skip to content

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 →

StatStat
  • For key numbers at the top of a dashboard or report.
import pyzed as pz
from 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)
Stat: Value onlyStat: Value only
Value only
Code
ui.stat("Build time", "1m 12s", width=190)
Stat: delta=12.5Stat: delta=12.5
delta=12.5
Code
ui.stat("Users", "1,284", delta=12.5, width=190)
Stat: delta=-8.0Stat: delta=-8.0
delta=-8.0
Code
ui.stat("Errors", "37", delta=-8.0, width=190)
Stat: trend=[...]Stat: trend=[...]
trend=[...]
Code
ui.stat("Revenue", "$9.4k", delta=4.2, trend=[3, 5, 4, 6, 8, 7, 9], width=190)

With inverse=True a drop is good news (green), for errors or latency.

Stat: icon=, inverse=TrueStat: icon=, inverse=True
icon=, inverse=True
Code
ui.stat("Errors", "12", delta=-8.0, inverse=True, icon="bug", width=180)
Stat: on_press=Stat: on_press=
on_press=
Code
ui.stat("Users", "1,204", delta=4.2, icon="users", on_press=on_press, width=180)

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().

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)
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).

Full reference →