Debugging interactive Rmarkdown (runtime: shiny) documents?

Interactive Rmarkdown documents, particularly with flexdashboard, are enticing, but everytime I go and try to build anything inside a Rmarkdown document with "runtime: shiny" in the frontmatter, I end up relatively quickly reverting back to a "conventional" shiny application because I can't easily debug in interactive Rmarkdown. Part of this is because the document must be "run", and by default, Rstudio "runs" it in a separate session that the user can't interact with. So any browser() statements are effectively ignored.

Is there a way to use browser() or something equivalent in an interactive Rmarkdown document? Are there other some best practices for building up a Shiny application (in Rmarkdown or otherwise)? For me, writing a shiny application typically involves dropping into a debugger from inside a reactive or render* statement and writing the code snippet I need while in the debugger. This works for me because then I can instantly run and test the code snippet right at the console. A key part of why this works is that browser() gets me into the environment where the expression will be actually be evaluated. Is there some better way to achieve this?

I'm eager to hear how others build up interactive Rmarkdown documents.


Calling rmarkdown::run(path_to_rmd) from the R console should let you run within the same R process. It might be nice to let you do the same from the Run Document button though, I agree.