The title says it all, how could I display display a confirmation modal before closing a Shiny app?
This is obviously possible to do it in JavaScript (e.g. javascript - Confirmation before closing of tab/browser - Stack Overflow ) but I was wondering if there's a built-in Shiny solution to do that in R.
You can use your preferred JS solution in shiny like this:
library(shiny)
ui <- fluidPage(
tags$script(HTML("
Shiny.initializedPromise.then(() => {
alert('test');
// your JS code
});"))
)
server <- function(input, output, session) {}
shinyApp(ui, server)
However, it seems to me that most custom JS solutions do not work reliably for different reasons:
javascript, forms
Thanks but I couldn't find an event that works well when closing the app. Sadly the onbeforeunload/beforeunload events don't seem to be robust solutions on the system I'm working on.
system
Closed
November 30, 2025, 1:50pm
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.