Skip to content

Fix running and debugging Shiny apps that are not the active editor - #119

Merged
seeM merged 2 commits into
mainfrom
fix/run-app-uri-argument
Sep 4, 2026
Merged

seeM merged 2 commits into
mainfrom
fix/run-app-uri-argument

Conversation

@seeM

@seeM seeM commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Shiny part of posit-dev/positron#15897. Positron Python part is in posit-dev/positron#15912.

Clicking Run Shiny App or Debug Shiny App above an app now runs that editor's file, even when a different editor is focused. The commands also take an optional uri, so an agent or a custom keybinding's args can run a file without first opening and focusing it.

In Positron, R apps run through the Run App API's new document option, so that half only takes effect once posit-dev/positron#15898 ships; the Python commands, which launch the terminal themselves, work today in both VS Code and Positron.

Python:

Screen.Recording.2026-09-03.at.16.53.23.mov

R:

Screen.Recording.2026-09-03.at.16.48.43.mov

Validation steps

Python (VS Code or Positron):

  1. Open app.py from a Shiny for Python app and click Run Shiny App in the editor title bar. Confirm the app runs and previews, as before.
  2. Open a second Shiny app file, other-app.py, in a split group beside it.
  3. Click into the app.py editor so it is the active editor, then click Run Shiny App in the other-app.py group's title bar.
  4. Confirm the terminal command names other-app.py, and that focus stays in the app.py editor.
  5. Repeat step 3 with Debug Shiny App and confirm the debug session starts on other-app.py.
  6. The negative case: with both files open and app.py active, run "Shiny: Run Shiny App" from the Command Palette. The palette passes no URI, so this should still run app.py.

R (needs a Positron build with posit-dev/positron#15898):

  1. Repeat steps 1–4 with two Shiny for R app files and Run Shiny App, and confirm the shiny::runApp() call in the console names the file whose button was clicked.
  2. Repeat step 6 with the R app files, and confirm the palette still runs the active editor's app.

The run and debug commands now take an optional uri and act on that
document, falling back to the active editor when called without one.
@seeM
seeM force-pushed the fix/run-app-uri-argument branch from cb686b3 to 969ff14 Compare September 4, 2026 14:01
seeM added a commit to posit-dev/positron that referenced this pull request Sep 4, 2026
)

Stacked on #15898.

The `positron-python` part of #15897. Shiny part:
posit-dev/shiny-vscode#119.

Clicking Run App or Debug App above a Python app now runs that editor's
file, even when a different editor is focused. The commands also take an
optional uri, so an agent or custom keybinding's args can run a file
without first opening and focusing it.


https://github.com/user-attachments/assets/2b8f7a08-8a81-4841-ac8c-d7268cae3fb6

### Release Notes

#### New Features

- N/A

#### Bug Fixes
- Run App and Debug App now run the file whose button was clicked rather
than the focused editor's file (#15897)

#### Validation Steps

@:apps

The Python Applications e2e suite already runs each app from its editor
title button, which is the URI path. New unit tests in
`extensions/positron-python/src/test/positron/webAppCommands.unit.test.ts`
cover a Uri argument, its string form, the debug commands, an empty
string, and an omitted argument: from extensions/positron-python, run
`npm run test:unittests -- --grep "Web app commands"`.

Manual steps:

1. In the `qa-example-content` workspace, open
`workspaces/python-apps/streamlit_example/streamlit_example.py` and
click Run App in the editor title bar. Confirm Streamlit runs and
appears in the Viewer, as before.
2. Open `workspaces/python-apps/dash_example/dash_example.py` in a split
group beside it.
3. Click into the Streamlit editor so it is the active editor, then
click Run App in the Dash group's title bar.
4. Confirm the Dash app runs (the terminal command, the progress
notification, and the Viewer all name `dash_example.py`), and that focus
stays in the Streamlit editor.
5. Repeat step 2 with the Debug App button in the Dash group's title bar
and confirm the debug session starts on `dash_example.py`.
6. The negative case: with both files still open and the Streamlit
editor active, run "Python: Run Dash App in Terminal" from the Command
Palette. The palette passes no URI, so this should still fall back to
the active editor and fail to run Dash from `streamlit_example.py`.

@gadenbuie gadenbuie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great, thank you! Just one small nitpicky comment

Comment thread src/run.ts Outdated
Comment on lines +548 to +552
// Parse rather than `Uri.file` so a scheme without slashes (untitled:,
// vscode-notebook-cell:) survives the round trip through a string.
return vscode.workspace.openTextDocument(
typeof uri === "string" ? vscode.Uri.parse(uri) : uri
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The tiniest nit-pick, but do you think it'd be a good idea to catch and handle errors here? I guess it'd only come up if a bad/invalid/stale Uri made it this far, which seems unlikely. But thought I'd mention it to see what you think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, good point. Fixed in 781179d. I'm still throwing, just a more helpful error message mentioning that we were trying to start a Shiny app and including the original error message at the end.

I went with a throw rather than directly showing an error notification because it will work well for both humans and agents:

  • An agent using the positronCommand tool will see the error in the tool result.
  • A human will see the error in a notification - VSCode already does this for errors in commands when invoked via the command palette and the editor toolbar.

@seeM
seeM merged commit 0c3d4eb into main Sep 4, 2026
6 checks passed
@seeM
seeM deleted the fix/run-app-uri-argument branch September 4, 2026 15:34
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.

2 participants