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

Hello,

I would like to use session$onSessionEnded(stopApp) inside a shiny application made with flexdashboard (https://rmarkdown.rstudio.com/flexdashboard/shiny.html)

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?