Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practise to debug shiny #162

Open
markschat opened this issue Apr 13, 2022 · 2 comments
Open

Best practise to debug shiny #162

markschat opened this issue Apr 13, 2022 · 2 comments

Comments

@markschat
Copy link

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:

  • Can shiny generally be debugged?
  • If so: what is the best way to do it?
@markschat
Copy link
Author

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
  1. Set VSCode workspace to the R projects root (e.g. File -> Open Folder... -> myProject)
  2. Create a debug configuration file (prompted for if opening debug tab in VSCode)

Debugging

  • Set your breakpoints using browser() (see https://shiny.rstudio.com/articles/debugging.html)
  • Run Debugger in Launch R-Workspace mode
  • Run shiny::runApp() in the debug console
  • Your app should fire up in a browser and the breakpoints pause the execution 🎉

@tomjemmett
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants