Skip to content

Conversation

@gadenbuie
Copy link
Collaborator

@gadenbuie gadenbuie commented Dec 5, 2025

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:

  • R apps with renv in subfolders - Apps can run from their subdirectory to pick up .Rprofile and the correct renv environment
  • Monorepo projects - Different apps can run from different directories based on their dependency structure
  • Shared dependency directories - Multiple apps can run from a common location

Changes

New Settings

shiny.runFrom - Global default working directory

  • Options: "projectRoot" (default) or "appDirectory"
  • Controls where all apps run by default
  • Backward compatible - defaults to "projectRoot" (current behavior)

shiny.runFromOverrides - Per-app directory overrides

  • Object mapping workspace-relative file paths to workspace-relative directory paths
  • Empty string "" means project root
  • Workspace-only setting (not synced to user settings)
  • Example: {"src/app.py": "src", "r-apps/app.R": ""}

New Command

"Shiny: Run this app from..." (shiny.setRunFromOverride)

  • Quick Pick UI with three options: Project Root, App Directory, Choose Folder...
  • Automatically updates all files for multi-file R apps (ui.R/server.R/global.R)
  • Always stores explicit user choices for configuration stability

Implementation

  • src/working-directory.ts: Resolves working directory using overrides → global default → graceful fallbacks
  • src/run.ts: Most of the integration happens here. When creating the terminal to run the app we set cwd to the configured app directory.
  • src/set-run-from-override-command.ts: Provides the "Run this app from..." command

Example 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:

  • Most apps run from their own directory (global default)
  • main/app.py runs from project root (override)
  • dashboard/app.R and the ui/server R app run from r-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:

  1. Use this feature to set the working directory
  2. Separately select the correct Python interpreter via the Python extension

We can address Python virtual environment detection in a future enhancement.

@gadenbuie gadenbuie requested a review from wch December 5, 2025 23:49
Copy link
Contributor

@wch wch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@wch wch merged commit 6a04ad7 into main Jan 6, 2026
4 checks passed
@wch wch deleted the feat/101-shiny-run-from-option branch January 6, 2026 19:26
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

Successfully merging this pull request may close these issues.

How to set Shiny terminal working directory for subfolder apps using renv (ref. positron #10960)

3 participants