Skip to content

Commit f269cb0

Browse files
committed
docs: Warn against using ui.modal(fade=True) when showing/hiding too quickly
Fixes #1318
1 parent ecc5c14 commit f269cb0

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

shiny/api-examples/modal_remove/app-core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from shiny import App, Inputs, Outputs, Session, reactive, ui
22

3+
MODEL_DELAY = 4
34

45
def run_model(delay=10.0):
56
import time
@@ -17,6 +18,7 @@ def the_modal():
1718
title="Running model",
1819
easy_close=False,
1920
footer=None,
21+
fade=MODEL_DELAY > 1
2022
)
2123

2224

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

37-
result = run_model(delay=4)
39+
result = run_model(delay=MODEL_DELAY)
3840

3941
# Now that we have model results, remove the modal
4042
# and update the model result reactive value

shiny/api-examples/modal_remove/app-express.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from shiny import reactive
22
from shiny.express import input, ui
33

4+
MODEL_DELAY=4
45

56
def run_model(delay=10.0):
67
import time
@@ -23,6 +24,7 @@ def the_modal():
2324
title="Running model",
2425
easy_close=False,
2526
footer=None,
27+
fade=MODEL_DELAY > 1
2628
)
2729

2830

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

35-
result = run_model(delay=4)
37+
result = run_model(delay=MODEL_DELAY)
3638

3739
# Now that we have model results, remove the modal
3840
# and update the model result reactive value

shiny/ui/_modal.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def modal(
9494
``modal_button()``, or from a call to ``modal_remove()`` on the server.
9595
fade
9696
If ``False``, the modal dialog will have no fade-in animation (it will simply
97-
appear rather than fade in to view).
97+
appear rather than fade in to view). When `fade=True`, be careful to avoid
98+
showing and hiding the modal too quickly. Only show and hide the modal when the
99+
intervening code takes at least 300 to 500ms to execute.
98100
**kwargs
99101
Attributes to be applied to the modal's body tag.
100102
@@ -193,6 +195,10 @@ def modal_remove(session: Optional[Session] = None) -> None:
193195
Modals can also be removed manually by the user if a :func:`~shiny.ui.modal_button`
194196
is provided, or if the modal is created with `easy_close=True`.
195197
198+
Be careful to avoid showing and hiding the modal too quickly when using
199+
`ui.modal(fade=True)`. The intervening code should take at least 300 to 500ms to
200+
execute (i.e. longer than it takes for the fade animation to reveal the modal).
201+
196202
Parameters
197203
----------
198204
session

0 commit comments

Comments
 (0)