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

Support launching Shiny apps via the run button in VS Code #1497

Open
joelostblom opened this issue Mar 4, 2024 · 4 comments
Open

Support launching Shiny apps via the run button in VS Code #1497

joelostblom opened this issue Mar 4, 2024 · 4 comments

Comments

@joelostblom
Copy link

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.

@ElianHugh
Copy link
Collaborator

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

@joelostblom
Copy link
Author

Thanks for the response! It seems like #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.

@sjmgarnier
Copy link

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

@joelostblom
Copy link
Author

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"
    },

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

No branches or pull requests

3 participants