Skip to content

Number

Number shows one number of its source, big: the latest, or an aggregate over a window, see Aggregating.

import dachshund
from dachshund.widgets import Number

with dachshund.row():
    dachshund.add(Number("cpu", title="CPU Load", unit="%"))

dachshund.emit("cpu", value=42)

dachshund.widgets.number.number.Number dataclass

Number(name, *, source='', title=None, actions=list(), action_args=dict(), persist=False, y='value', aggregate='last', over=None, unit=None)

Bases: AggregatedWidget

One number of its source, shown big: the latest, or an aggregate over a window.

Example

with dachshund.row():
    dachshund.add(Number("cpu", title="CPU Load", unit="%"))
    dachshund.add(Number("requests", aggregate="count", over=timedelta(hours=1)))
dachshund.emit("cpu", value=42)

Options

  • y (str) - The field read. Defaults to "value".
  • aggregate (str) - "last" for the latest number, or "count", "sum", "average", "min", "max" or "distinct" over over. Defaults to "last". See Aggregating.
  • over (timedelta | str) - The window: a timedelta back from now, or the current "day", "week" or "month" in the dashboard's timezone. Defaults to None, everything stored. Not for "last".
  • unit (str) - Shown next to the number, as is. Defaults to None.
  • persist (bool) - Keeps the latest number across restarts, for "last" only. Needs the dashboard's storage. Defaults to False.

unit class-attribute instance-attribute

unit = None

type class-attribute

type = 'number'

op class-attribute

op = 'replace'

script class-attribute

script = Path(__file__).parent / 'number.js'

style class-attribute

style = Path(__file__).parent / 'number.css'

render_value

render_value(value)
Source code in dachshund/widgets/number/number.py
44
45
def render_value(self, value: float | None) -> dict[str, Any]:
    return {"value": value, "unit": self.unit}