shiny.ui.modal#

shiny.ui.modal(*args, title=None, footer=<shiny.types.MISSING_TYPE object>, size='m', easy_close=False, fade=True, **kwargs)#

Creates the UI for a modal dialog, using Bootstrap’s modal class. Modals are typically used for showing important messages, or for presenting UI that requires input from the user, such as a user name and/or password input.

Parameters
  • args (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]]]]) – UI elements for the body of the modal.

  • title (Optional[str]) – An optional title for the modal dialog.

  • footer (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]]], MISSING_TYPE]) – UI for footer. Use None for no footer.

  • size (Literal[‘m’, ‘s’, ‘l’, ‘xl’]) – One of “s” for small, “m” (the default) for medium, or “l” for large.

  • easy_close (bool) – If True, the modal dialog can be dismissed by clicking outside the dialog box, or be pressing the Escape key. If False (the default), the modal dialog can’t be dismissed in those ways; instead it must be dismissed by clicking on a modal_button(), or from a call to modal_remove() on the server.

  • fade (bool) – If False, the modal dialog will have no fade-in animation (it will simply appear rather than fade in to view).

  • kwargs (Union[str, float, bool, None]) – Attributes to be applied to the modal’s body tag.

Return type

A UI element

Example

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

app_ui = ui.page_fluid(
    ui.input_action_button("show", "Show modal dialog"),
)

def server(input: Inputs, output: Outputs, session: Session):
    @reactive.Effect
    @reactive.event(input.show)
    def _():
        m = ui.modal(
            "This is a somewhat important message.",
            title="Somewhat important message",
            easy_close=True,
            footer=None,
        )
        ui.modal_show(m)


app = App(app_ui, server)