text_components¶
panel_flowdash.text_components
¶
Built-in text components: Markdown, rich text notes, headings and dividers.
MISSING_CLASS = 'fd-text-missing'
module-attribute
¶
TEXT_COMPONENTS = {'Text/Markdown': Markdown, 'Text/Notes': Notes, 'Text/Heading': Heading, 'Text/Divider': Divider}
module-attribute
¶
UNAVAILABLE = Unavailable('[unavailable]')
module-attribute
¶
_APP_MARKDOWN = markdown_renderer('gfm-like')
module-attribute
¶
_HEADING_VARIANTS = {'Title': 'h3', 'Heading': 'h4', 'Subheading': 'h5', 'Section': 'h6'}
module-attribute
¶
_HIDDEN = frozenset({'script', 'style', 'template', 'iframe', 'object', 'noscript', 'svg', 'math'})
module-attribute
¶
_HUGE_INT = 10 ** _MAX_DIGITS
module-attribute
¶
_HUGE_SPEC = re.compile('\\d{4,}')
module-attribute
¶
_INDENT = re.compile('^ql-indent-(\\d)$')
module-attribute
¶
_MARKDOWN = markdown_renderer('gfm-like', new_tab=False)
module-attribute
¶
_MARKDOWN_CSS = '\n:host {\n overflow: auto;\n font-family: var(--mui-typography-fontFamily, inherit);\n font-size: 14px;\n line-height: 1.5;\n color: var(--mui-palette-text-primary, var(--panel-on-background-color));\n}\n:host > div {\n box-sizing: border-box;\n padding: 0 12px;\n}\n:host > div > :first-child {\n margin-top: 0;\n}\nh1, h2, h3, h4, h5, h6 {\n font-weight: 500;\n line-height: 1.25;\n margin: 0.8em 0 0.4em;\n}\nh1 { font-size: 1.75em; }\nh2 { font-size: 1.4em; }\nh3 { font-size: 1.2em; }\nh4, h5, h6 { font-size: 1em; }\na {\n color: var(--mui-palette-primary-text, var(--mui-palette-primary-main, var(--panel-primary-color)));\n}\ntable {\n border-collapse: collapse;\n border: none;\n}\nth, td {\n padding: 4px 12px;\n border: none;\n border-bottom: 1px solid var(--mui-palette-divider, rgba(127, 127, 127, 0.25));\n text-align: left;\n}\nth {\n font-weight: 500;\n}\nimg {\n max-width: 100%;\n}\n.fd-text-missing {\n color: var(--mui-palette-text-secondary, inherit);\n font-size: 0.9em;\n font-style: italic;\n opacity: 0.85;\n}\n'
module-attribute
¶
_MAX_DEPTH = 3
module-attribute
¶
_MAX_DIGITS = 600
module-attribute
¶
_MAX_FILL = 1000
module-attribute
¶
_MAX_ITEMS = 50
module-attribute
¶
_MAX_TOTAL = 20 * _MAX_FILL
module-attribute
¶
_NOTES_CLASS = re.compile('^ql-(indent-[1-8]|align-(center|right|justify))$')
module-attribute
¶
_NOTES_CSS = '\n:host {\n --fd-notes-text: var(--mui-palette-text-primary, var(--panel-on-background-color));\n --fd-notes-muted: var(--mui-palette-text-secondary, rgba(127, 127, 127, 0.9));\n --fd-notes-divider: var(--mui-palette-divider, rgba(127, 127, 127, 0.25));\n --fd-notes-primary: var(--mui-palette-primary-text, var(--mui-palette-primary-main, var(--panel-primary-color)));\n --fd-notes-paper: var(--mui-palette-background-paper, var(--panel-background-color));\n}\n.ql-container.ql-bubble,\n.ql-container.ql-snow {\n border: none;\n font-family: var(--mui-typography-fontFamily, inherit);\n font-size: 14px;\n color: var(--fd-notes-text);\n}\n.ql-editor {\n padding: 8px 12px;\n line-height: 1.5;\n}\n.ql-editor h1, .ql-editor h2, .ql-editor h3 {\n font-weight: 500;\n margin: 0.4em 0 0.2em;\n}\n.ql-editor a {\n color: var(--fd-notes-primary);\n}\n.ql-editor ol {\n padding-left: 0;\n}\n.ql-editor > :first-child {\n margin-top: 0;\n}\n.ql-editor.ql-blank::before {\n left: 12px;\n right: 12px;\n color: var(--fd-notes-muted);\n font-style: normal;\n}\n.ql-bubble .ql-tooltip {\n z-index: 10;\n border-radius: 6px;\n background: var(--mui-palette-grey-900, #212121);\n box-shadow: var(--mui-shadows-4, 0 2px 8px rgba(0, 0, 0, 0.3));\n}\n.ql-bubble .ql-tooltip:not(.ql-flip) .ql-tooltip-arrow {\n border-bottom-color: var(--mui-palette-grey-900, #212121);\n}\n.ql-bubble .ql-tooltip.ql-flip .ql-tooltip-arrow {\n border-top-color: var(--mui-palette-grey-900, #212121);\n}\n:host(.fd-notes-editing) .ql-container:focus-within {\n border-radius: 6px;\n outline: 1px solid var(--fd-notes-primary);\n outline-offset: -2px;\n}\n'
module-attribute
¶
_NOTES_INLINE = frozenset({'strong', 'em', 'u', 's', 'code'})
module-attribute
¶
_NOTES_LINES = frozenset({'p', 'h1', 'h2', 'h3', 'li', 'blockquote'})
module-attribute
¶
_NOTES_LIST = frozenset({'bullet', 'ordered'})
module-attribute
¶
_NOTES_TAGS = frozenset({'p', 'br', 'h1', 'h2', 'h3', 'strong', 'em', 'u', 's', 'ol', 'ul', 'li', 'a', 'blockquote', 'code'})
module-attribute
¶
_NOTES_TOOLBAR = [[{'header': [1, 2, 3, False]}], ['bold', 'italic', 'underline', 'strike'], [{'list': 'ordered'}, {'list': 'bullet'}], ['link', 'blockquote', 'code'], ['clean']]
module-attribute
¶
_PRIVATE = re.compile('[\ue000-\ue003]')
module-attribute
¶
_SAFE_HREF = re.compile('^(https?:|mailto:)', re.IGNORECASE)
module-attribute
¶
_TEMPLATE_DOC = "\nPlaceholders are filled from the connected `value` and `table` inputs:\n`{{ value }}` shows the value, `{{ value.key }}` a key of a dict or a pandas\nSeries, and a format spec after a colon formats a number, e.g.\n`{{ value:,.0f }}` or `{{ value.share:.1% }}`. On a table (a DataFrame, e.g. a\nSQL query's `data`) `{{ table.column }}` is the first row's cell,\n`{{ table.column[2] }}` or `{{ table[2].column }}` the third row's and\n`{{ table.column[-1] }}` the last's. `{{#each table limit=5}}- {{ .region }}:\n{{ .share:.1% }}{{/each}}` repeats its text for each row, at most 50.\nPlaceholders do not compute: sort, filter and aggregate in the query."
module-attribute
¶
_WHITESPACE = re.compile('[ \\n\\r\\f]+')
module-attribute
¶
Divider
¶
Bases: Viewer
A horizontal rule with an optional label.
label = param.String(default='', label='Label', doc='Text shown in the middle of the rule.')
class-attribute
instance-attribute
¶
Filled
¶
Heading
¶
Bases: _FilledText
A heading for a section of the dashboard.
alignment = param.Selector(default='left', objects=['left', 'center', 'right'], label='Alignment', doc='How the heading and subtitle are aligned in the tile.')
class-attribute
instance-attribute
¶
size = param.Selector(default='Heading', objects=list(_HEADING_VARIANTS), label='Size', doc="How large the heading is, from 'Title' (largest) to 'Section'.")
class-attribute
instance-attribute
¶
subtitle = param.String(default='', label='Subtitle', doc='Smaller text below the heading.')
class-attribute
instance-attribute
¶
table = param.Parameter(default=None, doc="The table whose cells and rows fill the text's placeholders.")
class-attribute
instance-attribute
¶
text = param.String(default='Heading', label='Text', doc='The heading text.' + _TEMPLATE_DOC)
class-attribute
instance-attribute
¶
value = param.Parameter(default=None, doc="The value filled into the text's placeholders.")
class-attribute
instance-attribute
¶
Markdown
¶
Bases: _FilledText
Markdown text, optionally filled with values from upstream components.
table = param.Parameter(default=None, doc="The table whose cells and rows fill the text's placeholders.")
class-attribute
instance-attribute
¶
text = MultilineText(default='Write **Markdown** here.', label='Text', doc='The Markdown to show.' + _TEMPLATE_DOC, metadata={'flowdash': {'widget': 'code', 'language': 'markdown'}})
class-attribute
instance-attribute
¶
value = param.Parameter(default=None, doc="The value filled into the text's placeholders.")
class-attribute
instance-attribute
¶
Missing
¶
MultilineInput
¶
Bases: TextAreaInput
The text area a MultilineText config param is edited in, growing with its text.
MultilineText
¶
Bases: String
A String edited in a multi-line text area.
schema(safe=False, subset=None, mode='json')
¶
Notes
¶
Bases: Viewer
Rich text notes, edited in place while the dashboard is editable.
editing
property
¶
Whether the notes can be edited, as they can while the dashboard is and is not previewed.
placeholder = param.String(default='Write notes here', label='Placeholder', doc='Shown while the notes are empty and the dashboard is being edited.')
class-attribute
instance-attribute
¶
text = MultilineText(default='', label='Text', doc='\n The notes as HTML, typed into the tile itself rather than edited in\n the inspector. Only p, br, h1 to h3, strong, em, u, s, ol/ul/li,\n blockquote, inline code and http(s) or mailto links are kept;\n other elements, images, styles and attributes are dropped.', precedence=-1, metadata={'flowdash': {'two_way': True}})
class-attribute
instance-attribute
¶
_Budget
¶
_FilledText
¶
Bases: Viewer
A text tile filled from its value and table inputs, showing a failed input as unavailable.
_NotesLines
¶
Bases: HTMLParser
Split sanitized notes into the lines the editor shows, with their formats.
Quill rewrites the HTML it is given into its own form: it joins blocks without whitespace, collapses spaces, splits a paragraph at each line break, drops trailing empty paragraphs, nests indented list items and wraps loose text in a paragraph. Two markups that give the same lines show the same notes.
_NotesSanitizer
¶
_TextExtractor
¶
_clip(text)
¶
_format(value, spec, depth)
¶
_huge(value)
¶
Whether value is a number too large or small to write out in full.
_items(value, depth, mapping)
¶
_lookup(value, key)
¶
_prepare(template, tables, problems=None)
¶
_scientific(value, spec)
¶
check_text(config, inputs)
¶
Warn about placeholders of a text tile that read a column or row its table does not have.
escape_markdown(text)
¶
Escape text so a Markdown pane shows it verbatim, without HTML, formatting or math.
fill_placeholders(template, pattern, fill, escape=str)
¶
Replace each match of pattern in template by escape(fill(match)), within the length budget.
fill_template(template, value, escape=str, table=None)
¶
Replace the {{ value }} and {{ table }} placeholders of template, each filled text through escape.
fill_text(template, tables, escape=str, problems=None)
¶
Return template with its placeholders filled from the values and tables named in tables.
Its blocks are repeated first (see :mod:panel_flowdash.text_fill), then
each placeholder is replaced by its value passed through escape, once:
a value is never read as a placeholder. Problems, such as a column a
table does not have, are added to problems.
format_value(value, spec='')
¶
Return value as the text a placeholder shows, formatted by spec if it applies.
The text is at most a thousand characters: a collection shows its first items, and a number too long to write out is shown in scientific notation. A value that cannot be shown gives its type's name.
html_to_text(markup)
¶
Return the text of markup with tags dropped and one line per block.
is_failure(value)
¶
Whether value is a failure carried along an edge as a param.ReactiveError.
is_plain(value)
¶
Whether value is plain data whose text is the data itself, not an object's internals.
markdown_renderer(preset='commonmark', new_tab=True)
¶
Return a Markdown renderer that shows raw HTML as typed.
With new_tab its links open in a new tab, since a link followed in the app's own tab would leave the dashboard and any unsaved edits behind; a link to an anchor on the page stays in it. Exported documents keep plain links.
markdown_with_placeholders(template, pattern, fill, value_class=None)
¶
Render template as HTML, replacing each match of pattern by the text fill(match) gives.
Placeholders are filled after parsing, so a value is always literal text: it
cannot add markup, and inside a code span or block it keeps its backslashes.
A placeholder in a link or image URL is dropped rather than filled, so
showing the text never sends upstream data to another site. With
value_class, each value in the text is a <span> of that class. A
marker for something the text names but cannot show (a :class:Missing)
is a <span> of class :data:MISSING_CLASS.
names_pattern(names)
¶
Return a pattern matching exactly one of names, the start of a placeholder.
notes_lines(markup)
¶
Return the lines markup shows in the Notes editor, to compare notes regardless of form.
notes_markdown(markup)
¶
Return notes as Markdown: headings, lists, quotes, bold, italic, code and links.
prepare(template, root, namespace, format, lookup, problems=None)
¶
Repeat the blocks of template over their tables and return it with its filler.
root is the pattern of the names placeholders start with, namespace maps the first part of such a name to its value, format writes a value by a format spec and lookup picks a name from a value that is not a table. A block over no data yet repeats nothing; one over a value that is not a table, an unclosed or a nested one shows a problem. Each problem is added to problems, once.
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.
render_markdown(template, value, table=None)
¶
Render template as HTML, filling its {{ value }} and {{ table }} placeholders.
render_text(template, tables, value_class=None, problems=None)
¶
Render template as HTML, filling its placeholders from the values and tables named in tables.
See :func:markdown_with_placeholders for how values are kept literal.
safe_str(value)
¶
Return str(value) for plain data and the object's label for anything else.
sanitize_notes(markup)
¶
Return markup reduced to the elements, links and classes the Notes editor produces.
summarize_value(value, limit=60)
¶
Describe a port value in a few words, e.g. "72,357 rows, 29 columns".
text_typography(text, **params)
¶
Return a pmui.Typography showing text, a string or a reactive one, as literal text.