Skip to content

Conversation

@juliasilge
Copy link
Contributor

@juliasilge juliasilge commented Dec 23, 2025

This PR addresses:

This PR changes the preview behavior to keep track of the source terminal when in Positron, to instrument the new red stop button:

Screenshot 2025-12-23 at 12 52 10 PM

The red stop button should appear quite soon after you click the "play" button for either an R or Python Shiny app (it is not IMMEDIATE and I am wondering if we should try to hurry that up on the Positron side with an optimistic assumption that the app will start) and stay visible while the app is running.

  • If you click the stop button while the app is running, the app should stop and then the Viewer pane should clear.
  • If you do Ctrl+C in the terminal while the app is running, the app should also stop and the Viewer pane should also clear.
Screenshot 2025-12-23 at 1 13 41 PM

Just FYI, we have this functionality built in to Positron for other app types we support, like Streamlit and Dash and such. We need this change here to support the button for Shiny. Unfortunately, we don't have a lot of good options for testing here in the extension (no Positron test runner for extensions yet), but we can extend the Playwright tests we have in Positron once this change is in a released version of the extension. We do currently test this button for a Streamlit app and similar.

This does not effect any behavior when in VS Code.

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 good overall, but I think it would be better if we could get this to work in VS Code as well as Positron, so that Shiny users who use VS Code (or other forks) can also have a stop button. I realize this implementation uses some Positron-specific features, but I'll look into getting this to work in non-Positron as well.

Comment on lines 41 to 42
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const previewSourceType = (pst as any).PreviewSourceType;
Copy link
Contributor

Choose a reason for hiding this comment

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

The as isn't necessary here.

Suggested change
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const previewSourceType = (pst as any).PreviewSourceType;
const previewSourceType = pst.PreviewSourceType;


/**
* Positron only: Get the preferred runtime for a language from Positron's API.
* Used to find R interpreter path in Positron. Returns undefined in VS Code.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just as a heads up, this also applies to the Python interpreter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, I've updated this on main.

@wch
Copy link
Contributor

wch commented Jan 5, 2026

I added some changes so that a stop button also appears in VS Code, which uses the Simple Browser for the app instead of Postron's Viewer panel.

When the app is running, a stop button appears in the Simple Browser when it is active:
image

And when the editor panel with the app file is active, it also shows a stop button there:
image

That latter case is supposed to also work in Positron, but I think there may be a bug in Positron related to displaying icons dynamically. In the package.json, there's the following:

      "editor/title/run": [
        {
          "command": "shiny.stopApp",
          "group": "navigation@-1",
          "when": "shiny.appRunning && (shiny.python.active || shiny.r.active)"
        }
      ],
      "editor/title": [
        {
          "command": "shiny.stopApp",
          "group": "navigation",
          "when": "shiny.appRunning && (shiny.python.active || shiny.r.active)"
        }
      ]

The editor/title/run entry controls the visibility of Stop Shiny App in dropdown menu for the Run button, and the editor/title entry controls the visibility of the button. In Positron, the first one works, but the second one does not seem to. Notice that Stop Shiny App is present below, but the Stop button is not:

image

It's the same logic for both, but only one of them shows up.

However, if I remove the when condition entirely (so that the button is always visible) the Stop button does appear initially, when the app isn't running, but then disappears after the app starts.

      "editor/title": [
        {
          "command": "shiny.stopApp",
          "group": "navigation"
        }
      ]
positron-shiny-stop-button-compressed.mp4

@wch wch merged commit 4a4a26e into posit-dev:main Jan 5, 2026
4 checks passed
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