Another way would be to hide a shiny button and programmatically "click" the button when you close your app. An observe({myButton(); shutdown() }) could be executed when the button value changes. This is a round-about way to solve it, but uses native shiny hooks.
Thanks! I read that guide. Is the correct Javascript method shiny.onSessionEnded? I looked through the shiny.js code on Github and could not find it listed explicitly and it is not discussed in the article.
I imagine because it is registered as a callback function when the shiny app starts it won't be listed in the source code.