-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: Add support for running Shiny for R apps #30
Conversation
In package.json we take a dependency on the |
src/run-r.ts
Outdated
? "shiny::devmode()" | ||
: "options(shiny.autoreload = TRUE)"; | ||
|
||
const runApp = `${devOrReload}; shiny::runApp("${path}", port=${port}, launch.browser=FALSE)`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${path}
needs escaping here. Not only for edge cases but on Windows the path will contain backslashes (I assume).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC escapeCommandForTerminal()
handles this, It's pretty aggressive and has worked in my testing. In fact, the R code in runApp
isn't inside quotes because it's handled correctly by escapeCommandForTerminal()
(on my system at least, I may be missing something about how that function works).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are actually two issues happening here:
-
I've just used
Rscript
as the command which likely won't work on Windows, where we might need the full path to the Rscript binary, e.g."C:\Program Files\R\R-3.6.0\bin\Rscript.exe"
. -
Typically, I'd use
Rscript -e 'shiny::runApp("app.R")'
in my terminal, but when I used this formulationescapeCommandForTerminal()
broke the command by escaping"
within the''
quotes.
Given the above, I've refactored the rRunApp()
command to use a packaged runShinyApp.R
script that takes commandline arguments for path
, port
and --devmode
.
That means that the escaping now works as expected, but leaves us with the problem of figuring out the full path to Rscript.exe
on Windows. Do you have any ideas about how to approach that problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you refactor to use runShinyApp.R
only because of the escapeCommandForTerminal()
behavior? We can definitely fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can count on rig, this is my first time even hearing of it. You can see how the R extension does it here (and RStudio does something similar):
https://github.com/REditorSupport/vscode-R/blob/d582b9184838a32352f624e451d4c1856f347b9c/src/util.ts#L98
https://github.com/REditorSupport/vscode-R/blob/d582b9184838a32352f624e451d4c1856f347b9c/src/util.ts#L63
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcheng5 I've implemented this using the vscode-R extension as inspiration. I also tested locally on a Windows VM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you refactor to use
runShinyApp.R
only because of theescapeCommandForTerminal()
behavior? We can definitely fix that.
It might have started out this way, but we also run shiny::devmode()
or set options(shiny.autoreload)
before running the app. With that and the port-setting logic, I found it a lot easier to use a separate R script than to try to build the R code in strings.
I did add some logic to echo the shiny::runApp()
command so users could copy and paste the command into an R console.
Are these two entries in "extensionDependencies": [
"ms-python.python"
],
"dependencies": {
"@vscode/python-extension": "^1.0.5"
} I generally agree with you, but I don't think we need to do that work yet. I think it'd be okay for us to require the Python extension for now (it's a very popular extension and I'd imagine the number of R users who are using VSCode but not that extension is currently rather small). |
|
I implemented making the Python extension a soft dependency, but I don't feel that strongly about it either way. |
Co-authored-by: Joe Cheng <joe@posit.co>
Closes #29
shiny.python.runApp
into a newshiny.r.runApp
command.shiny.r.debugApp
(yet)shiny::devmode()
before running the app whenshiny.r.devmode
istrue
oroptions(shiny.autoreload = TRUE)
whenfalse
(to maintain the reload feature).Todo
Shiny
terminal?shiny::devmode()
oroptions(shiny.autoreload = TRUE)
before running the app and both appear to be working as expected.Shiny > Python > Port
option is for both.shiny.port
but I couldn't find a good mechanism for migrating users fromshiny.python.port
toshiny.port
.true
Rscript
on Mac/Linux orRscript.exe
if on WindowsRscript.exe
on Windows?