How to use session$onSessionEnded to kill the app with flexdashboard shiny app


I would like to use session$onSessionEnded(stopApp) inside a shiny application made with flexdashboard (

The problem is that according to:

the code should go inside the server function but in a flexdashboard shiny app there is not a server function.

How can I make it work for a shiny app made with flexdashboard?