shiny.ui.notification_show#

shiny.ui.notification_show(ui, action=None, duration=5, close_button=True, id=None, type='default', session=None)#

Show a notification to the user.

Parameters
  • ui (Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]) – Content of message.

  • action (Optional[TagList]) – 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 action content.

  • duration (Union[int, float, None]) – Number of seconds to display the message before it disappears. Use None to make the message not automatically disappear.

  • close_button (bool) – If True, display a button which will make the notification disappear when clicked. If False do not display.

  • id (Optional[str]) – 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’]) – A string which controls the color of the notification. One of “default” (gray), “message” (blue), “warning” (yellow), or “error” (red).

  • session (Optional[Session]) – A Session instance. If not provided, it is inferred via get_current_session().

Return type

The notification’s id.

Example

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
from shiny import *

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)