Alert#
Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).
Material version available
pn.ui.Alert resolves to the Material Design implementation of this component,
documented in the panel-material-ui reference.
This page documents the classic pn.pane.Alert.
import panel as pn
pn.extension()
The Alert pane allows providing contextual feedback messages for typical user actions with the handful of available and flexible alert messages.
It’s heavily inspired by the Bootstrap Alert.
Parameters:#
For details on other options for customizing the component see the layout and styling how-to guides.
alert_type(str, default=’primary’): The type of Alert and one ofprimary,secondary,success,danger,warning,info,light,dark.escape(bool, default=False): Whether to render theobjectas preformatted plain text, escaping any HTML and skipping Markdown rendering, e.g. to display untrusted text such as error messages.object(str): The contextual feedback message, which may contain Markdown or HTML.
Since the Alert pane is a subclass of the Markdown pane it also supports all of its parameters, e.g. renderer, extensions and dedent.
The Alert pane supports Markdown and HTML syntax:
pn.pane.Alert('## Alert\nThis is a warning!')
The Alert pane also provides a number of alert_type options which control the color of the alert message:
text = (
"This is a **{alert_type}** alert with [an example link]"
"(https://panel.holoviz.org/). Give it a click if you like."
)
pn.Column(*[
pn.pane.Alert(text.format(alert_type=at), alert_type=at)
for at in pn.pane.Alert.param.alert_type.objects],
sizing_mode="stretch_width"
).servable()
It may also be used for longer messages:
text = """
### Well done!
Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.
<hr>
Did you notice the use of the divider?
"""
pn.pane.Alert(text, alert_type="success")
When displaying text you do not control, e.g. an error message that may contain user input, set escape=True to render the object as preformatted plain text instead of interpreting it as Markdown and HTML:
pn.pane.Alert("KeyError: '<b>not bold</b>'\n *not emphasized*", alert_type="danger", escape=True)
Like any other pane, the Alert can be updated by setting the object or alert_type parameters, e.g. to reflect the outcome of an action:
alert = pn.pane.Alert("Processing your request...", alert_type="info")
alert
alert.param.update(object="Your request completed successfully!", alert_type="success");
Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).