widgets¶
panel_flowdash.widgets
¶
Built-in controls and views for FlowDash dashboards.
BUILTIN_COMPONENTS = {'Widgets/Select': Select, 'Widgets/MultiChoice': MultiChoice, 'Widgets/RadioGroup': RadioGroup, 'Widgets/Slider': Slider, 'Widgets/RangeSlider': RangeSlider, 'Widgets/NumberInput': NumberInput, 'Widgets/DateRange': DateRange, 'Widgets/Toggle': Toggle, 'Widgets/TextInput': TextInput, 'Widgets/KPI': KPI, 'Widgets/Image': Image, 'Data/FilterBySelection': SelectionFilter, **TEXT_COMPONENTS}
module-attribute
¶
TEXT_COMPONENTS = {'Text/Markdown': Markdown, 'Text/Notes': Notes, 'Text/Heading': Heading, 'Text/Divider': Divider}
module-attribute
¶
_COLORS = ['primary', 'secondary', 'success', 'warning', 'danger']
module-attribute
¶
_COMMON_CONFIG = ['label', 'description', 'min_widget_width']
module-attribute
¶
_CSS_COLOR = re.compile('^(#[0-9a-fA-F]{3,8}|[a-zA-Z]{3,24}|(rgb|hsl)a?\\([0-9\\s.,%/+-]{1,40}\\))$')
module-attribute
¶
_FIELD_SIZE = {'width': 360, 'height': 90}
module-attribute
¶
_IMAGE_CSS = '\n:host {\n min-height: 60px;\n}\n.fd-image {\n box-sizing: border-box;\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n}\n.fd-image img {\n display: block;\n width: 100%;\n height: 100%;\n}\n.fd-image-empty {\n font-family: var(--mui-font-family, inherit);\n font-size: 0.875rem;\n color: var(--mui-palette-text-secondary, color-mix(in srgb, currentColor 65%, transparent));\n}\n'
module-attribute
¶
_INT_FORMAT = '0'
module-attribute
¶
_ISO_DATE = '^(\\d{4}-\\d{2}-\\d{2})?$'
module-attribute
¶
_KPI_CSS = '\n:host {\n container-type: inline-size;\n --fd-kpi-muted: var(--mui-palette-text-secondary, color-mix(in srgb, currentColor 65%, transparent));\n}\n.fd-kpi {\n box-sizing: border-box;\n height: 100%;\n padding: 8px 14px;\n display: flex;\n flex-direction: column;\n justify-content: center;\n gap: 2px;\n min-width: 0;\n font-family: var(--mui-font-family, inherit);\n color: var(--mui-palette-text-primary, inherit);\n}\n.fd-kpi-label {\n /* Clear of the notes an untitled tile floats in its top-right corner. */\n margin-right: max(0px, calc(var(--fd-tile-corner-width, 0px) - 8px));\n font-size: 0.75rem;\n font-weight: 500;\n letter-spacing: 0.08em;\n line-height: 1.6;\n text-transform: uppercase;\n color: var(--fd-kpi-muted);\n}\n.fd-kpi-label, .fd-kpi-value, .fd-kpi-delta {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n@container (max-width: 200px) {\n .fd-kpi {\n padding: 8px 10px;\n }\n .fd-kpi-label {\n white-space: normal;\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n line-height: 1.4;\n }\n}\n.fd-kpi-value {\n font-size: clamp(1.5rem, 13cqi, 3rem);\n font-weight: 500;\n line-height: 1.2;\n font-variant-numeric: tabular-nums;\n}\n.fd-kpi-empty {\n color: var(--fd-kpi-muted);\n}\n.fd-kpi-delta {\n font-size: 0.8125rem;\n line-height: 1.5;\n color: var(--fd-kpi-muted);\n}\n.fd-kpi-change {\n font-weight: 500;\n font-variant-numeric: tabular-nums;\n}\n.fd-kpi-good {\n color: var(--mui-palette-success-main, #2e9d4a);\n}\n.fd-kpi-bad {\n color: var(--mui-palette-error-main, #d84a3a);\n}\n'
module-attribute
¶
_PERIODS = {'last_7_days': 7, 'last_30_days': 30, 'last_90_days': 90, 'last_365_days': 365}
module-attribute
¶
_SAFE_URL = re.compile('^(https?://|/|\\./|\\.\\./|data:image/(png|jpe?g|gif|webp|svg\\+xml|avif);base64,)|^[A-Za-z0-9_][A-Za-z0-9_./%-]*([?#][^\\s\\"\'<>]*)?$', re.IGNORECASE)
module-attribute
¶
_SLIDER_FORMAT = pmui.FloatSlider.param.format.default
module-attribute
¶
_SLIDER_MARGIN = (10, 20)
module-attribute
¶
_SLIDER_SIZE = {'width': 360, 'height': 100}
module-attribute
¶
_THEME_COLORS = {'primary': ('primary', '#1976d2'), 'secondary': ('secondary', '#9c27b0'), 'success': ('success', '#2e9d4a'), 'warning': ('warning', '#ed6c02'), 'error': ('error', '#d84a3a'), 'danger': ('error', '#d84a3a'), 'info': ('info', '#0288d1')}
module-attribute
¶
_TOGGLE_SIZE = {'width': 360, 'height': 72}
module-attribute
¶
CheckWarning
¶
Bases: str
A message a config check returns that does not refuse the config.
Return it in place of a problem string, alone or in the list of problems, for something the check could not verify, e.g. a query whose probe timed out. The config is applied all the same, and the warning shown with it.
DateRange
¶
Bases: _WidgetComponent
Pick a range of dates.
custom_end = _ISODate(doc="Last date of the 'custom' period, as YYYY-MM-DD.")
class-attribute
instance-attribute
¶
custom_start = _ISODate(doc="First date of the 'custom' period, as YYYY-MM-DD.")
class-attribute
instance-attribute
¶
default_end = _ISODate(label='Latest date', doc='Latest selectable date as YYYY-MM-DD while no end is wired; empty for none.')
class-attribute
instance-attribute
¶
default_period = param.Selector(default='last_30_days', objects=[*_PERIODS, 'month_to_date', 'year_to_date', 'all', 'custom'], label='Default period', doc="\n Range selected when the dashboard opens. Relative periods end today, 'all'\n spans the bounds (no selection without bounds), and 'custom' uses\n custom_start and custom_end. A period outside the bounds selects\n all of them, or, when only one is set, moves to it and keeps its length.")
class-attribute
instance-attribute
¶
default_start = _ISODate(label='Earliest date', doc='Earliest selectable date as YYYY-MM-DD while no start is wired; empty for none.')
class-attribute
instance-attribute
¶
end = param.Date(default=None, allow_None=True)
class-attribute
instance-attribute
¶
label = param.String(default='Date Range')
class-attribute
instance-attribute
¶
min_widget_width = param.Integer(default=300)
class-attribute
instance-attribute
¶
size = param.Selector(default='medium', objects=['small', 'medium', 'large'])
class-attribute
instance-attribute
¶
start = param.Date(default=None, allow_None=True)
class-attribute
instance-attribute
¶
value = param.DateRange(default=None, allow_None=True)
class-attribute
instance-attribute
¶
variant = param.Selector(default='outlined', objects=['outlined', 'filled', 'standard'])
class-attribute
instance-attribute
¶
selected()
¶
Image
¶
Bases: Viewer
An image from a URL.
alt = param.String(default='', label='Alt text', doc='Text describing the image.')
class-attribute
instance-attribute
¶
default_url = param.String(default='', label='URL', doc='Image URL shown while no url is wired.')
class-attribute
instance-attribute
¶
fit = param.Selector(default='contain', objects=['contain', 'cover', 'fill', 'scale-down', 'none'], doc="\n How the image fills its tile: 'contain' shows all of it, 'cover' fills\n the tile and crops, 'fill' stretches it.")
class-attribute
instance-attribute
¶
url = param.String(default=None, allow_None=True)
class-attribute
instance-attribute
¶
KPI
¶
Bases: Viewer
A headline number, with its change from a reference value.
caption = param.String(default='', doc="Muted text after the change, e.g. 'vs last month'.")
class-attribute
instance-attribute
¶
delta = param.Selector(default='percent', objects=['percent', 'absolute', 'none'], doc='How the change from a wired reference is shown.')
class-attribute
instance-attribute
¶
format = param.String(default='', doc="\n Python format spec of the number, e.g. ',.0f', '.1%' or '.2e'. Empty\n shows whole numbers with thousands separators and others with two decimals.", metadata={'flowdash': {'widget': 'format'}})
class-attribute
instance-attribute
¶
increase_is_good = param.Boolean(default=True, label='Increase is good', doc='Color a rise green and a fall red; off reverses the colors, e.g. for costs.')
class-attribute
instance-attribute
¶
label = param.String(default='KPI', doc='Heading shown above the number.')
class-attribute
instance-attribute
¶
prefix = param.String(default='', doc="Text before the number, e.g. '$'.")
class-attribute
instance-attribute
¶
reference = param.Number(default=None, allow_None=True)
class-attribute
instance-attribute
¶
suffix = param.String(default='', doc="Text after the number, e.g. ' kWh'.")
class-attribute
instance-attribute
¶
thresholds = param.List(default=[], doc='\n Ascending [limit, color] pairs that color the number: it takes the color\n of the first pair whose limit it does not exceed, e.g. [[50, "error"],\n [80, "warning"], [100, "success"]]. Colors are theme names (primary,\n secondary, success, warning, error, info) or CSS colors.', metadata={'flowdash': {'widget': 'thresholds'}})
class-attribute
instance-attribute
¶
value = param.Number(default=None, allow_None=True)
class-attribute
instance-attribute
¶
MultiChoice
¶
Bases: _OptionsWidget
Choose multiple values from configured or wired options.
label = param.String(default='MultiChoice')
class-attribute
instance-attribute
¶
max_items = param.Integer(default=0, bounds=(0, None), doc='Maximum selections, 0 for no limit.')
class-attribute
instance-attribute
¶
placeholder = param.String(default='', doc='Text shown while nothing is selected.')
class-attribute
instance-attribute
¶
searchable = param.Boolean(default=True, doc='Filter the options by typing.')
class-attribute
instance-attribute
¶
value = param.List(default=[])
class-attribute
instance-attribute
¶
variant = param.Selector(default='outlined', objects=['outlined', 'filled', 'standard'])
class-attribute
instance-attribute
¶
selected()
¶
NumberInput
¶
Bases: _NumberWidget
Type a number, optionally within wired bounds.
default_value = param.Number(default=0, doc='Value shown when the input is placed.')
class-attribute
instance-attribute
¶
label = param.String(default='Number Input')
class-attribute
instance-attribute
¶
size = param.Selector(default='medium', objects=['small', 'medium', 'large'])
class-attribute
instance-attribute
¶
value = param.Number(default=0, allow_None=True)
class-attribute
instance-attribute
¶
variant = param.Selector(default='outlined', objects=['outlined', 'filled', 'standard'])
class-attribute
instance-attribute
¶
selected()
¶
RadioGroup
¶
Bases: _OptionsWidget
Pick one of a few options shown side by side.
color = param.Selector(default='primary', objects=_COLORS)
class-attribute
instance-attribute
¶
label = param.String(default='Radio Group')
class-attribute
instance-attribute
¶
orientation = param.Selector(default='horizontal', objects=['horizontal', 'vertical'], doc='Lay the options out in a row or a column.')
class-attribute
instance-attribute
¶
size = param.Selector(default='medium', objects=['small', 'medium', 'large'])
class-attribute
instance-attribute
¶
style = param.Selector(default='radio', objects=['radio', 'buttons'], doc='Radio buttons with labels, or a joined row of toggle buttons.')
class-attribute
instance-attribute
¶
value = param.Parameter(default=None)
class-attribute
instance-attribute
¶
selected()
¶
RangeSlider
¶
Bases: _BoundedSlider
Select a numeric range within configured or wired bounds.
Select
¶
Bases: _OptionsWidget
Select a value from configured or wired options.
label = param.String(default='Select')
class-attribute
instance-attribute
¶
searchable = param.Boolean(default=False, doc='Filter the options by typing.')
class-attribute
instance-attribute
¶
size = param.Selector(default='medium', objects=['small', 'medium', 'large'])
class-attribute
instance-attribute
¶
value = param.Parameter(default=None)
class-attribute
instance-attribute
¶
variant = param.Selector(default='outlined', objects=['outlined', 'filled', 'standard'])
class-attribute
instance-attribute
¶
selected()
¶
SelectionFilter
¶
Bases: Viewer
The rows of a DataFrame that match a selection.
data = param.DataFrame(default=None, allow_None=True, doc='The rows to filter.')
class-attribute
instance-attribute
¶
selection = param.ClassSelector(class_=Selection, default=None, allow_None=True, doc='The selection rows must match.')
class-attribute
instance-attribute
¶
filtered()
¶
Return the rows of data matching selection, all of them without one.
Slider
¶
Bases: _BoundedSlider
Select a numeric value within configured or wired bounds.
TextInput
¶
Bases: _WidgetComponent
Enter a line of text.
default_value = param.String(default='', doc='Text in the field when it is placed.')
class-attribute
instance-attribute
¶
label = param.String(default='Text Input')
class-attribute
instance-attribute
¶
placeholder = param.String(default='', doc='Hint shown while the field is empty.')
class-attribute
instance-attribute
¶
size = param.Selector(default='medium', objects=['small', 'medium', 'large'])
class-attribute
instance-attribute
¶
update_on = param.Selector(default='enter', objects=['enter', 'typing'], doc='\n When the text is sent downstream: on Enter or when the field loses\n focus, or on every keystroke, which suits cheap filters.')
class-attribute
instance-attribute
¶
variant = param.Selector(default='outlined', objects=['outlined', 'filled', 'standard'])
class-attribute
instance-attribute
¶
text()
¶
Toggle
¶
Bases: _WidgetComponent
Turn an option on or off.
color = param.Selector(default='primary', objects=_COLORS)
class-attribute
instance-attribute
¶
default_value = param.Boolean(default=False, doc='Whether it is on when placed.')
class-attribute
instance-attribute
¶
label = param.String(default='Toggle')
class-attribute
instance-attribute
¶
size = param.Selector(default='medium', objects=['small', 'medium', 'large'])
class-attribute
instance-attribute
¶
style = param.Selector(default='switch', objects=['switch', 'checkbox'])
class-attribute
instance-attribute
¶
checked()
¶
_BoundedSlider
¶
Bases: _NumberWidget
A slider over configured bounds, which wired start and end inputs override.
color = param.Selector(default='primary', objects=_COLORS, doc='Theme color of the track and handles.')
class-attribute
instance-attribute
¶
default_end = param.Number(default=100, doc='Upper bound while no end is wired.')
class-attribute
instance-attribute
¶
default_start = param.Number(default=0, doc='Lower bound while no start is wired.')
class-attribute
instance-attribute
¶
show_value = param.Boolean(default=True, doc='Show the current value next to the label.')
class-attribute
instance-attribute
¶
_ISODate
¶
Bases: String
A date as a YYYY-MM-DD string, or empty, that must name a real day.
schema(safe=False, subset=None, mode='json')
¶
_NumberWidget
¶
Bases: _WidgetComponent
Shared handling of whole and fractional numbers for the numeric widgets.
end = param.Number(default=None, allow_None=True)
class-attribute
instance-attribute
¶
format = param.String(default='', doc="Numeral.js format of the value, e.g. '0.0' or '0%'. Empty picks one for the number type.")
class-attribute
instance-attribute
¶
is_integer
property
¶
Whether the widget currently selects integers.
number_type = param.Selector(default='auto', objects=['auto', 'integer', 'float'], doc='\n Whether the widget selects integers or floats. Auto picks integers when\n the bounds, step and default value are all whole numbers.')
class-attribute
instance-attribute
¶
start = param.Number(default=None, allow_None=True)
class-attribute
instance-attribute
¶
step = param.Number(default=1, bounds=(0, None), inclusive_bounds=(False, True), doc='Increment between selectable values, e.g. 1 or 0.5.')
class-attribute
instance-attribute
¶
_OptionsWidget
¶
Bases: _WidgetComponent
A widget choosing from configured options, or from options wired to its input.
_WidgetComponent
¶
Bases: Viewer
Shared config for the built-in widgets, applied live to the wrapped widget.
description = param.String(default='', doc='Tooltip shown next to the label.')
class-attribute
instance-attribute
¶
label = param.String(default='')
class-attribute
instance-attribute
¶
min_widget_width = param.Integer(default=240, bounds=(80, 1200), label='Minimum width', doc='\n Canvas nodes shrink to their content, which gives a stretching widget no\n room, so this sets how wide the widget is there. Tiles still stretch it.')
class-attribute
instance-attribute
¶
_as_date(value)
¶
_css_color(color)
¶
Return a CSS color for a theme color name or a plain CSS color, or None if unsafe.
_format_number(value, spec)
¶
_horizontal_margin(widget)
¶
_parse_date(value)
¶
check_kpi(config, inputs)
¶
Refuse a format or thresholds the KPI cannot use, as its inspector fields do.
A value the dashboard already holds only warns, so a KPI saved with one stays editable and loads and saves it unchanged; a change that brings in a new one is refused.
format_problem(spec)
¶
Return why spec is no format for a number, in words, or None if it is one.
register(*, page=True, component=False, sidebar=False, title=None, icon=None, description=None, tags=None, extensions=None, default_size=None, min_size=None, max_size=None, framed=None, singleton=False, provides=None, requires=None, placeholder=None, config_schema=None, config=None, config_editor=None, check_config=None, contract=None, config_choices=None, config_completions=None, palette_presets=None, handles_failures=None, aliases=None, port_aliases=None, allow_users=None, allow_groups=None, deny_users=None, deny_groups=None, authorize=None)
¶
Metadata-only decorator for app exports.
Annotates an app object/callable without altering runtime behavior.
The config_schema, config and config_editor arguments declare
design-time configuration options that appear in the node editor. Use
config_schema (a param.Parameterized subclass, a Pydantic model, or
a JSON Schema dict) to define config explicitly, or config to name which
of a Viewer's own params are configuration rather than input ports. Pass
config_editor to supply a custom editor callable instead of the
auto-generated form.
The check_config argument takes a callable, sync or async, that checks
a node's config before it is applied: check(config, inputs) gets the
node's whole config with the change applied and its input values that are
set and not failed ({} before the node is placed). It returns None,
a string or an iterable of strings, each non-empty string a problem, or
raises ValueError with the problem as its message. A
:class:~panel_flowdash.CheckWarning in place of a string is a warning,
shown with the config but not refusing it. Any other result or exception,
or taking longer than 10 seconds, counts as a failed check. The check runs
again when an input of the node is connected or disconnected.
A sync check runs in a worker thread and must not change the editor. A
config with problems is refused in the inspector and by the agent tools,
and reported by validation and previews.
The contract argument takes a
:class:~panel_flowdash.ParameterContract: what the dashboard needs of
a value bound to a parameter on one of the component's config fields,
e.g. the columns its downstream nodes read from a data source. Its
expects(context) writes the parameter's expects and its
check(context, expects) runs whenever the parameter is rebound,
see :mod:panel_flowdash.parameters.
The config_choices argument takes a callable, sync or async, called
like check_config as choices(config, inputs), that returns the
values each config field may take: {field: choices}, where choices are
a list of values, a {label: value} dict or a
:class:~panel_flowdash.Choices. The inspector offers them in a dropdown,
or as suggestions with Choices(restrict=False), and asks again when
the node's inputs or config change. Choices under the name of an input
are offered for the value that input takes while it is not connected. A
config param may also declare that
it names a column of an input, with
metadata={"flowdash": {"choices": "columns", "of": "<input>"}}.
The config_completions argument takes a callable, sync or async,
called like config_choices, that returns the words the code editor
of a code field completes while typing: {field: words}, where words
are a list, a {label: word} dict or a
:class:~panel_flowdash.Choices whose types are shown beside each
word, e.g. the columns of the tables a query reads. Without it a code
field completes the column names of the node's tabular inputs.
The palette_presets argument takes a callable, called with the
editor's context, that returns further entries the component
palette and the command palette offer for the component, each placing
it with a config filled in: dicts with a title and a config, and
optionally a description, a tooltip, tags and an icon,
e.g. one entry per data source the host provides. It is asked again
when the editor's context changes, not on every search; an entry without
a title or config, or whose config is not JSON-serializable, is
skipped, and a failing callable offers none. An entry's optional id
identifies it in the command palette; without one, its title and config
do. Components found by scanning a project directory offer their presets
once imported, which the app does when a dashboard is edited.
The placeholder argument sets the message a dashboard tile shows while a
blocking input of the component is unset, in place of the default
"Waiting for
The handles_failures argument names the inputs that can receive a
failure. With FlowDash(propagate_failures=True) an upstream failure
reaches such an input as a param.ReactiveError instead of leaving the
input on its last value; the parameter behind it must accept one, so use an
untyped param.Parameter.
The aliases argument lists ids the component was registered under
before (e.g. ["Old/section_name"]) and port_aliases maps former
port or config names to current ones (e.g. {"ticker": "symbol"}), so a
saved dashboard that references the old names still loads after a rename.
The framed argument says whether the component's dashboard tile is
drawn as a framed card: False for components that are layout chrome
themselves, e.g. a divider or a section heading, True for ones that
need a frame, and None (the default) to follow the dashboard's "Frame
tiles" setting. A tile's own frame option, set in the Layout tab, takes
precedence over it.
The extensions argument names the Panel extensions (e.g.
["tabulator"]) the app's output needs. Components are imported lazily,
after the page has loaded its JavaScript, so an editor loads every declared
extension up front; an undeclared one fails to render in the browser.
The allow_users, allow_groups, deny_users and deny_groups
arguments declare page-level authorization rules. Users are matched against
either the OAuth login or the system user; groups against the identity's
resolved group membership. Deny rules always win; when only allow rules are
present the identity must match at least one; with no rules the project's
default policy applies. Pass authorize for a custom callable taking the
resolved Identity and returning a bool (resolved on import).
The returned decorator exposes the metadata as its record before it is
applied, so a factory that builds the class can read the registered title
and the rest of the declaration while it builds it::
registration = register(component=True, title=spec["title"])
if not spec.get("columns"):
raise ValueError(f"{registration.record.title}: declares no columns.")
return registration(type(name, (Viewer,), namespace))
Arguments register refuses, and a component class it refuses, are
named by their title when one is given rather than by the Python name.
safe_image_url(url)
¶
Return url when it is an http(s), relative or base64 image data URL, else None.
stored_config()
¶
Return the config the node has now, while a check of a change to it runs.
None while a node that is not placed yet is checked. A check can use it to refuse only what a change brings in, and to warn about values a dashboard already holds, so an old dashboard stays editable.
thresholds_problems(thresholds)
¶
Return what is wrong with a list of [limit, color] pairs, empty if nothing is.