Skip to content

Commit

Permalink
docs: Warn against using ui.modal(fade=True) when showing/hiding to…
Browse files Browse the repository at this point in the history
…o quickly

Fixes #1318
  • Loading branch information
gadenbuie committed Dec 31, 2024
1 parent ecc5c14 commit f269cb0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion shiny/api-examples/modal_remove/app-core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from shiny import App, Inputs, Outputs, Session, reactive, ui

MODEL_DELAY = 4

def run_model(delay=10.0):
import time
Expand All @@ -17,6 +18,7 @@ def the_modal():
title="Running model",
easy_close=False,
footer=None,
fade=MODEL_DELAY > 1
)


Expand All @@ -34,7 +36,7 @@ def do_run_model():
# Show the modal, blocking interaction with the UI
ui.modal_show(the_modal())

result = run_model(delay=4)
result = run_model(delay=MODEL_DELAY)

# Now that we have model results, remove the modal
# and update the model result reactive value
Expand Down
4 changes: 3 additions & 1 deletion shiny/api-examples/modal_remove/app-express.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from shiny import reactive
from shiny.express import input, ui

MODEL_DELAY=4

def run_model(delay=10.0):
import time
Expand All @@ -23,6 +24,7 @@ def the_modal():
title="Running model",
easy_close=False,
footer=None,
fade=MODEL_DELAY > 1
)


Expand All @@ -32,7 +34,7 @@ def do_run_model():
# Show the modal, blocking interaction with the UI
ui.modal_show(the_modal())

result = run_model(delay=4)
result = run_model(delay=MODEL_DELAY)

# Now that we have model results, remove the modal
# and update the model result reactive value
Expand Down
8 changes: 7 additions & 1 deletion shiny/ui/_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def modal(
``modal_button()``, or from a call to ``modal_remove()`` on the server.
fade
If ``False``, the modal dialog will have no fade-in animation (it will simply
appear rather than fade in to view).
appear rather than fade in to view). When `fade=True`, be careful to avoid
showing and hiding the modal too quickly. Only show and hide the modal when the
intervening code takes at least 300 to 500ms to execute.
**kwargs
Attributes to be applied to the modal's body tag.
Expand Down Expand Up @@ -193,6 +195,10 @@ def modal_remove(session: Optional[Session] = None) -> None:
Modals can also be removed manually by the user if a :func:`~shiny.ui.modal_button`
is provided, or if the modal is created with `easy_close=True`.
Be careful to avoid showing and hiding the modal too quickly when using
`ui.modal(fade=True)`. The intervening code should take at least 300 to 500ms to
execute (i.e. longer than it takes for the fade animation to reveal the modal).
Parameters
----------
session
Expand Down

0 comments on commit f269cb0

Please sign in to comment.