ui.notification_show
ui.notification_show(
ui,*,
=None,
action=5,
duration=True,
close_buttonid=None,
type='default',
=None,
session )
Show a notification to the user.
A notification is a message that appears near the bottom corner of the app. Notifications normally disappear after a short period of time, and should multiple notifications appear together, they will stack on top of one another.
Parameters
ui : TagChild
-
Contents of the notification message.
action : Optional[TagChild] = None
-
Message content that represents an action. For example, this could be a link that the user can click on. This is separate from ui so customized layouts can handle the main notification content separately from the action content.
duration : Optional[int | float] = 5
-
Number of seconds to display the message before it disappears. Use
None
to prevent the message from disappearing automatically. The user will need to click the corner of the notification to close it. close_button : bool = True
-
If
True
, display a button which will make the notification disappear when clicked. IfFalse
do not display. id : Optional[str] = None
-
An optional unique identifier for the notification. If supplied, any existing notification with the same
id
will be replaced with this one (otherwise, a new notification is created). type : Literal[âdefaultâ, âmessageâ, âwarningâ, âerrorâ] = 'default'
-
A string which controls the color of the notification. This should be one of âdefaultâ (gray), âmessageâ (blue), âwarningâ (yellow), or âerrorâ (red).
session : Optional[
Session
] = None-
The Session in which the notification should appear. If not provided, the session is inferred via get_current_session.
Returns
: str
-
The notificationâs
id
.
See Also
Examples
#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
## file: app.py
from shiny import App, Inputs, Outputs, Session, reactive, ui
app_ui = ui.page_fluid(
ui.input_action_button("show", "Show"),
" ",
ui.input_action_button("remove", "Remove"),
)
def server(input: Inputs, output: Outputs, session: Session):
ids: list[str] = []
n: int = 0
@reactive.effect
@reactive.event(input.show)
def _():
nonlocal ids
nonlocal n
# Save the ID for removal later
id = ui.notification_show("Message " + str(n), duration=None)
ids.append(id)
n += 1
@reactive.effect
@reactive.event(input.remove)
def _():
nonlocal ids
if ids:
ui.notification_remove(ids.pop())
app = App(app_ui, server, debug=True)