(One caveat for runtime: shiny apps, regardless of which option you choose: your Rmd is not rendered until well after the browser page has loaded, so you can’t rely on the DOMContentLoaded event, or its jQuery equivalent, $(document).ready() .)
In an Rmarkdown with runtime: shiny I have also tried
I wonder if runtime:shiny_prerendered could be the solution here ? One reason it exists:
The traditional way to add Shiny components to an R Markdown document is through the use of runtime: shiny. (...)
However, because it requires a full document render for each end user browser session it can perform poorly for documents that don’t render quickly.
For information, there is a dedicated page on https://rmarkdown.rstudio.com/authoring_shiny_prerendered.html
Personally I used it to speed up the opening of an Rmd document with shiny element. Basically, all the Rmd chunk are run once. I let you try if it changes thinks for you. The function is rmarkdown BTW.