shiny
shiny copied to clipboard
global onStop running before session onStop
I'm not sure if this behaviour is intended - it seems to be the case, that a global onStop callback (application shutdown) is running before the session level onStop callback when stopping a shiny app.
I would have expected it to happen the other way around.
I stumbled upon this due to a cleanup conflict like this:
library(shiny)
global_var <- 10
shinyApp(
ui = basicPage("onStop demo",
br(),
actionButton("stopapp", "Stop App")),
server = function(input, output, session) {
observeEvent(input$stopapp, {
stopApp()
})
onStop(function() {
cat("Running session onStop:\n")
print(global_var)
cat("Session stopped\n")
})
},
onStart = function() {
cat("Doing application setup\n")
onStop(function() {
cat("Running global onStop: Doing application cleanup\n")
rm("global_var", envir = globalenv())
})
}
)
I just came across this behaviour again. Would be great if anyone could check if this is intended.