vscode-R icon indicating copy to clipboard operation
vscode-R copied to clipboard

Support launching Shiny apps via the run button in VS Code

Open joelostblom opened this issue 11 months ago • 4 comments

Is your feature request related to a problem? Please describe.

When I try to run a shiny application by clicking the Play/Run button, VS Code opens the R console and executes the line:

source("path/to/app.R", encoding = "UTF-8")

However, this does not actually run the shiny app (I tried from a standalone terminal too with the same result). Instead, it seems like I need to type runApp(path/toapp.R') manually into the VS Code terminal to actually launch the shiny application.

I tried this with a simple skeleton in a file called app.R.

library(shiny)


ui <- fluidPage(
  "Hello, world!"
)

server <- function(input, output, session) {}

shinyApp(ui, server)

Describe the solution you'd like

Something similar to the extension for Shiny for Python (and RStudio), where there is an option to added to the run button which says "Run shiny app".

Describe alternatives you've considered

Typing runApp('app.R') manually into the R console. I maybe bind a hotkey to this, but it would be convenient to have a solution that is there by default, especially when teaching with VS Code for R.

joelostblom avatar Mar 04 '24 23:03 joelostblom

I agree that this would be a nice to have feature, though I think it would extend beyond Shiny (e.g., plumber APIs). I initially looked into this in #794, but didn't have time to explore it much further

ElianHugh avatar Mar 05 '24 07:03 ElianHugh

Thanks for the response! It seems like https://github.com/REditorSupport/vscode-R/issues/1099 is also related to your point about extending this to more file types. I was initially thinking that some logic from https://github.com/posit-dev/pyshiny-vscode could be borrowed but that would only cover the Shiny scenario (although that might be one of the more common use cases? I'm not sure).

I am exploring using VS Code instead of R Studio for teaching purposes, and this is one of the areas where R Studio is currently more convenient/intuitive for new learners. For my personal use cases, I will keep using runApp and bind a hotkey if possible.

joelostblom avatar Mar 05 '24 16:03 joelostblom

I wholeheartedly support this feature request. I work with Shiny all the time and this is the only thing I really miss from RStudio.

sjmgarnier avatar Mar 10 '24 12:03 sjmgarnier

As a workaround I'm using something like this in my keybindings.json, but it requires there to be an open terminal to send to.

    {
      "key": "Ctrl+Shift+d",
      "command": "workbench.action.terminal.sendSequence",
      "args": { "text": "R -e \"shiny::runApp('${file}')\"\u000D" },
      "when": "editorTextFocus && editorLangId == r"
    },

joelostblom avatar Mar 13 '24 22:03 joelostblom