Add configurable working directory for Shiny app launch #102
+396
−23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #101
Summary
This PR adds support for configuring the working directory used when launching Shiny apps. Users can now control whether apps run from the workspace root, the app's directory, or a custom location.
This is particularly useful for:
.Rprofileand the correct renv environmentChanges
New Settings
shiny.runFrom- Global default working directory"projectRoot"(default) or"appDirectory""projectRoot"(current behavior)shiny.runFromOverrides- Per-app directory overrides""means project root{"src/app.py": "src", "r-apps/app.R": ""}New Command
"Shiny: Run this app from..." (
shiny.setRunFromOverride)Implementation
src/working-directory.ts: Resolves working directory using overrides → global default → graceful fallbackssrc/run.ts: Most of the integration happens here. When creating the terminal to run the app we setcwdto the configured app directory.src/set-run-from-override-command.ts: Provides the "Run this app from..." commandExample Configuration
{ "shiny.runFrom": "appDirectory", "shiny.runFromOverrides": { "src/apps/main/app.py": "", "r-apps/dashboard/app.R": "r-apps", "r-apps/ui/ui.R": "r-apps", "r-apps/ui/server.R": "r-apps" } }In this example:
main/app.pyruns from project root (override)dashboard/app.Rand the ui/server R app run fromr-apps(custom override)Known Limitations
Python virtual environments: This feature controls the working directory but does not automatically detect or activate Python virtual environments. Python apps still use the interpreter selected via the Python extension's "Select Interpreter" command.
For Python apps with virtual environments in subdirectories, users need to:
We can address Python virtual environment detection in a future enhancement.