I would like to run code conditionally on whether the user closed the app or the app crashed.
The session$onSessionEnded runs regardless of how the session ended. And I did not find some other function or variable inside session that looked like it could be an indicator on how the session ended.
Basically I would like to use something similar to the commented code in the sample app below. Where crashed would be printed if I click the button, but user ended would be printed if I close the app (eg, close the browser).
library(shiny)
ui <- fluidPage(actionButton('crash', 'crash me'))
server <- function(input, output, session){
observeEvent(input$crash, stop())
session$onSessionEnded(function() {
# if (crashed){
# print('crashed')
# }else{
# print('user ended')
# }
})
}
shinyApp(ui, server)