Modal

#| standalone: true
#| components: [viewer]
#| viewerHeight: 400

## file: app.py
from shiny import App, reactive, ui

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

def server(input, output, 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=ui.modal_button("Dismiss"),
        )
        ui.modal_show(m)

app = App(app_ui, server)
from shiny import reactive
from shiny.express import ui, input

ui.input_action_button("show", "Show modal dialog")

@reactive.effect
@reactive.event(input.show)
def show_important_message():
    m = ui.modal(  
        "This is a somewhat important message.",  
        easy_close=True,  
        footer=None,  
    )  
    ui.modal_show(m)
from shiny import App, reactive, ui

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

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

app = App(app_ui, server)
No matching items

Relevant Functions

  • ui.modal
    ui.modal(*args, title=None, footer=MISSING, size='m', easy_close=False, fade=True, **kwargs)

  • ui.modal_show
    ui.modal_show(modal, session=None)

  • ui.modal_remove
    ui.modal_remove(session=None)

  • ui.modal_button
    ui.modal_button(label, icon=None, **kwargs)

No matching items

Details

A modal is a dialog box that appears in front of the app. You can use modals to display messages, curate the user experience, or collect user input, like passwords and usernames.

To create a modal, first assemble the components of the modal with ui.modal() and save them to an object. Then call ui.modal_show() on the object to display the modal.

Typically, you will want to create a reactive effect to call ui.modal_show() whenever a particular event occurs. For example, the reactive effect below will open a modal whenever the value of input.show() changes.

@reactive.effect
@reactive.event(input.show)
def _():
    m = ui.modal( 
        "This is a somewhat important message.",
        title="Somewhat important message",
        easy_close=True
    )
    ui.modal_show(m)

Variations

No matching items