Basic Usage
At minimum, a Metric needs alabel and a value. The label names the statistic, and the value is the headline number that catches the eye. Values can be strings or raw numbers — strings are displayed as-is, so you have full control over formatting.
When the value comes from state, use reactive expressions with pipes to format it at display time. Here the raw number 42000000 becomes $42M by dividing, rounding, and wrapping in literal $ and M characters — no Python formatting needed.
Description
Add adescription for extra context below the headline number. This is the right place for time ranges, data sources, percentile qualifiers, or any caveat that helps readers interpret the number correctly. Without it, a value like “142ms” could mean anything — with it, the reader knows exactly what they’re looking at.
Trend Indicator
Pass adelta to show a change indicator alongside the value. Metric automatically infers the trend direction and color from the delta’s sign: positive deltas get a green up arrow, negative deltas get a red down arrow.
Inverted Sentiment
The auto-inference assumes “up is good, down is bad,” which works for most metrics but breaks for things like response time, error rates, or costs — anything where going up is bad news. Override the automatic coloring by settingtrend_sentiment explicitly. The arrow still points in the direction the number moved, but the color reflects whether that movement is good or bad.
Here response time increased by 18ms. Without the override, a positive delta would get a green arrow. Setting trend_sentiment="negative" makes it red, correctly signaling that slower is worse.
KPI Row
The classic dashboard header: a row of Metric cards spanning the top of a page. Wrap each Metric in a Card for visual separation and use a Grid to give every card equal width. This pattern scales naturally — add or remove cards and the grid reflows without manual width calculations.Dashboard Layout
Metrics shine as the top row of a full dashboard, giving users an at-a-glance summary before they dive into the detail below. Use a Dashboard grid to place Metric cards across the first row, then put a chart below that spans the full width. EachDashboardItem controls its position and size on the 12-column grid, so you can mix metric widths and chart spans freely.
The h-full class on each Card ensures they stretch to fill their grid cell, keeping the row visually aligned even if some metrics have longer descriptions than others.
API Reference
Metric Parameters
The metric name displayed above the value (e.g.
"Revenue", "Active Users").The headline number. Strings are displayed as-is, so pre-format with currency symbols, commas, or units as needed.
Optional text below the value for additional context like time ranges or data sources.
Change indicator shown next to the value (e.g.
"+23.4%", "-15", "+$2.3M"). When present, an arrow icon and sentiment color are automatically inferred from the sign.Arrow direction:
"up", "down", or "neutral". Inferred from delta when omitted — positive deltas point up, negative point down.Color control:
"positive" (green), "negative" (red), or "neutral" (muted). Inferred from trend when omitted — up is positive, down is negative. Override this for inverted metrics where down is good (e.g. costs decreasing).Additional Tailwind CSS classes.
Protocol Reference
Metric