I do have a bit of code executed within session$onSessionEnded() (such as a DBI::dbDisconnect()) of a Shiny app and I wonder the best practice to trigger it directly from the R code (for instance when a condition is not met, you close the app but also want to trigger this bit of code).
stop() will stop the R code (but not the app itself letting a "ghost" app) whereas stopApp() will close the app without triggering the session$onSessionEnded()
Should I for instance create a function that I should call before stopApp()ing or is there a way to tell to the application to trigger the session$onSessionEnded()? Like a session$endSession()?