shiny icon indicating copy to clipboard operation
shiny copied to clipboard

global onStop running before session onStop

Open ismirsehregal opened this issue 3 years ago • 1 comments

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())
    })
  }
)

ismirsehregal avatar Mar 15 '23 14:03 ismirsehregal

I just came across this behaviour again. Would be great if anyone could check if this is intended.

ismirsehregal avatar Nov 14 '23 14:11 ismirsehregal