'How to debug R-Shiny code with VS Code

Is there any way to debug Shiny (R) inside VS Code? I can easily debug Shiny apps inside RStudio but I like to code inside VS Code so looking for the way to debug R code inside VS Code.



Solution 1:[1]

Seems, shiny can be debugged in VSCode using browser-statements ?

Prerequisites

  • Setup this VSCode extensions (VSCode R Guide)
    • R (by Yuki Ueda)
    • R Debugger
  • Use a default app structure (see docs of appDir when running ?shiny::runApp for possible setups)
  • Set your VSCode workspace to the R projects root (e.g. File -> Open Folder... -> myProject)

Debugging

  • Set your breakpoints using browser() (RStudio Article)
  • Run R-Debugger in Launch R-Workspace mode
  • Execute shiny::runApp() in the Debug Console as soon the Debugger pauses
  • Your app should fire up in a browser and the breakpoints pause the execution ?

Further Ressources

  • VSCode Article on debugging (can be very helpfull)
  • Issue on this topic in the VSCode-R-Debugger repo

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1