-
Notifications
You must be signed in to change notification settings - Fork 100
ui.modal_remove fails unless fade is set to False #1318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @Pierre-Bartet! The real culprit is
The second option is less common, typically with Here's an example (run the app on shinylive) using from shiny import App, Inputs, Outputs, Session, reactive, ui
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",
fade=False,
easy_close=False,
footer=ui.modal_button("Close"),
)
ui.modal_show(m)
app = App(app_ui, server) |
Hi and thanks for the answer.
doesn't work (except when deactivating fading). |
My apologies, I missed that detail in your post -- because the code was in the screenshot, I went to the docs and tried to recreate your issue rather than being able to run your example directly. I agree that we should have individual examples for The problem with your original post is that you've included The idea of from shiny import App, Inputs, Outputs, Session, reactive, ui
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(
ui.p("This is a somewhat important message."),
ui.p(
"All done? ",
ui.input_action_link("close", "Close the modal.")
),
title="Somewhat important message",
fade=False,
easy_close=False,
footer=None
)
ui.modal_show(m)
@reactive.effect
@reactive.event(input.close)
def _():
ui.modal_remove()
app = App(app_ui, server) |
Thanks for the explanation!
I thought that first but was then confused by the weird interaction with fading. |
I have also seen issues where a modal fails to close based on ui.modal_remove(). In my case, the modal contains a loading icon while data is processed via a model. It is hard to provide an example because it seems intermittent where the modal doesnt close. However, I dont want the user be able to click off the dialog and close the loading bar when the processing is happening so easy_close should be false. My temporary fix has been to add a sleep after the function before the ui.modal_remove is called @reactive.effect
@reactive.event(input.btn_run_model)
def runModel():
data = v_data()
m = get_loading_modal("Running Model")
ui.modal_show(m, session=session)
results = run_model(data) # can take 10-30 seconds to run
v_results.set(results)
ui.modal_remove(session=session)
|
Thanks @corey-dawson. My guess is that as long as Here's a complete example (also on shinylive) that demonstrates the issue: import time
from shiny import reactive
from shiny.express import input, render, ui, session
def run_model(delay=10.0):
start_time = time.time()
while time.time() - start_time < delay:
pass
return time.time()
def the_modal():
return ui.modal(
"The model is running, please wait.",
title="Running model",
easy_close=False,
footer=None,
)
ui.input_action_button("run", "Run Model")
v_results = reactive.value()
@reactive.effect
@reactive.event(input.run)
def runModel():
ui.modal_show(the_modal())
# adjust the delay in seconds down to zero
results = run_model(delay=2)
v_results.set(results)
ui.modal_remove() If you adjust the model running delay down to a small value close to or equal to zero, the modal is shown but doesn't go away. After working with this example a bit, I couldn't find a way to restructure the server logic to reliably avoid this problem. I'm beginning to suspect that this is a subtle side-effect of the client-side |
I tried closing the modal in a separate effect, but the problem is still there (probably because it is still inside the same reactive tick): @reactive.effect
@reactive.event(input.run)
def runModel():
ui.modal_show(the_modal())
results = run_model(delay=0)
v_results.set(results)
@reactive.effect
@reactive.event(v_results)
def remove_modal():
ui.modal_remove() |
I can't reproduce this in Shiny for R using the same app; I now think this bug is specific to Shiny for Python. |
It's possible that it's happening in Python and not R because Python sends the back-to-back messages closer together. I dug into it a little bit and I think the problem has to do with the Bootstrap Modal component. I stepped through the code I noticed that when the From https://getbootstrap.com/docs/4.0/components/modal/#methods:
So one possibility is in our |
I looked at it a bit more, and I can think of some other solutions to this, but they are kind of complicated for this small issue -- maybe it would be best to just wait for a tick before calling |
It seems that the problem is not there anymore (1.2.1), does it mean it is fixed now? |
I think the issue still exists. Try the app linked in #1318 (comment) with |
Indeed, the example in the documentation doesn't remove the modal when the model run fast. |
I've fixed this upstream but need to port the fix to Shiny for Python |
In the documentation example of
ui.modal_remove
, actually trying to use it fails (the modal is never removed), unlessfade
is set toFalse
.The text was updated successfully, but these errors were encountered: