ManuelHentschel / VSCode-R-Debugger

R Debugger Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=RDebugger.r-debugger
MIT License
170 stars 11 forks source link

Best practise to debug `shiny` #162

Open markschat opened 2 years ago

markschat commented 2 years ago

I just switched to VSCode for writing Shiny-Apps with custom JS. Loving the experience so far 🤩 thank´s for this great package btw as it adds ton of value! An issue I stumbled upon is that I can´t find any ressources on how to debug shiny using the VSCode-R-Debugger. My own attempts failed.

My question is:

markschat commented 2 years ago

Could´nt give up on the idea of using VSCode as my main IDE for R (dark mode, git integration, JS, ... 🥰).

Here is a solution I came up with that seem to work.

Prerequisites

  1. Install/ configure VSCode extensions R (by Yuki Ueda) and R Debugger
  2. Use default shiny app structure (see ?shiny::runApp() for possible setups) Example:
    myProject/
    ├── app.R
    ├── R/
    │   ├── module.R
  3. Set VSCode workspace to the R projects root (e.g. File -> Open Folder... -> myProject)
  4. Create a debug configuration file (prompted for if opening debug tab in VSCode)

Debugging

tomjemmett commented 2 years ago

I've found that shiny::runApp() / shiny::shinyApp() will both only actually run the app when print() is called, so changing your script to

app <- shiny::runApp()
print(app)

will probably be what you want to use (with a Launch R-File mode profile)