shiny::stopApp() in an application to do some cleanup to the R-environment when the user clicks a link to close an app (e.g., delete some functions and variables defined in global.R). This works fine when the app is run “external” in Chrome and Safari. However, when I use Rstudio viewer, the viewer window does not consistently close when
shiny::stopApp() is called. Sometimes it clears and sometimes the greyed-out app is still shown, as is the “Reload app” button, even though the app has been stopped.
Is there a way to force an Rstudio viewer window with a running Shiny app to close on
stopbuttons in Rstudio do consistently stop the app and close the viewer window. However, when the user clicks the stop button the cleanup functions in my app won’t be called. Is there a way, from inside a shiny app running in a viewer window, to “catch” when an Rstudio stop button is pressed by the user?