Giter VIP home page Giter VIP logo

shiny-vscode's Introduction

Shiny - VS Code Extension

This is an extension to help launch Shiny applications. Shiny is a package for Python and R that is designed to make it easy to build interactive web applications with the powerful data and scientific features of Python and R.

Features

Run and Debug Shiny Apps

The main features of this extension are additional options in the Run button menu when editing an app.py or app.R file to "Run Shiny App" or "Debug Shiny App" (Python only).

Run app

It also provides a couple of code snippets in both Python and R:

  • shinyapp for creating a new Shiny application
  • shinymod for creating a new Shiny module
  • shinyexpress for creating a new Shiny Express application (Python)

For a complete Shiny for Python experience in VS Code, please visit our docs for more information, including instructions for configuring the type checker and debugger for use with Shiny.

Shinylive

You can use the extension to create shareable links to your apps using Shinylive, a free service for sharing Shiny apps via static hosting. Shinylive links encode the app's code and data in the URL, so you can share your app with others without needing to deploy it to a server. When the link is opened, the app runs in the user's browser using special version of Python or R that can run in the browser.

To create a Shinylive link from your app, you have two choices:

  1. For single-file apps, e.g. app.py or app.R, run the Create ShinyLive Link from Active File from the command palette with the app file open and active.

  2. For multi-file apps, select all of the files or directories you want to include in your Shinylive app in the Explorer pane. Then right click on the selection and choose Create ShinyLive Link from Selected Files.

The Shiny extension will ask you which app mode you want to use (display the app or show an editor next to the app) and what action to take (to open or copy the link).You can also configure these options in the extension settings.

For the reverse operation, use the Save App from Shinylive Link command in the command palette to save an app and its files from a Shinylive link. You'll be prompted to paste the Shinylive link and then to choose where the app will be saved in your workspace.

Extension Settings

This extension contributes the following settings for Python and R.

Python

  • shiny.python.port: The port number to listen on when running a Shiny for Python app. (By default, 0, which will choose a random port for each workspace.)
  • shiny.python.debugJustMyCode: When running the "Debug Shiny App" command, only step through user-written code. Disable this to allow stepping through library code. (Defaults to true.)

Note that there is no setting for Python executable path or virtual environment. This extension uses whatever Python environment the VS Code Python extension thinks is active. If you find that the "Run Shiny App" and "Debug Shiny App" commands are launching with a different version of Python or different virtual environment than you intended, use the Python extension's Select Interpreter command to change it.

R

  • shiny.r.port: The port number to listen on when running a Shiny app. (By default, 0, which will choose a random port for each workspace.)
  • shiny.r.devmode: When true (default), Shiny for R apps are launched in developer mode.

Shinylive

  • shiny.shinylive.appMode: Should the Shinylive link open the app in "app" mode, showing only the app and an optional header, or in "editor" mode with the app alongside an editor and console pane. The default is "ask", which prompts you each time you create Shinylive link.
  • shiny.includeHeader: Include the "Shiny" header in the Shinylive link when opening in app mode?
  • shiny.shinylive.openAction: What action should be taken when opening a Shinylive link? Options are "open" to open the link in an external browser, "copy" the link to the clipboard, or "ask". The default is "ask", which prompts you each time you create a Shinylive link.
  • shiny.shinylive.host: The Shinylive host used when creating a Shinylive link. The default is "https://shinylive.io", which uses the latest released version of Shiny in Python or R. Or "https://posit-dev.github.io/shinylive", which uses the latest development version of Shiny in Python or R.

shiny-vscode's People

Contributors

gadenbuie avatar gregswinehart avatar jcheng5 avatar wch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shiny-vscode's Issues

Spaces in path causes issue

c:\Users\xxxxxx\OneDrive - BD\Documents\Projects\ShinyPython.venv\Scripts\python.exe -m shiny run --port 51127 --reload "c:\Users\xxxxxx\OneDrive - BD\Documents\Projects\ShinyPython\app.py"

'c:\Users\xxxxxx\OneDrive' is not recognized as an internal or external command,
operable program or batch file.

If you put double quotes on the first part it works.

Specify interpreter in configuration

Thank you for this great extension! 🌻

Currently, the "Run" button defaults to the main interpreter (e.g. /usr/bin/python3). Is there a way to specify a different interpreter in Settings? I'm inside a conda environment and right now I'm just doing shiny run --reload and that works, but would be neat to just click a button.

extension defaulting to /usr/bin/python3, but using /usr/local/bin/python

When I try to run my Shiny python app with the extension via the run button, I get the following:

/usr/bin/python3 -m shiny run --port 45287 --reload "/workspaces/MY_APP/app.py"
/usr/bin/python3: No module named shiny

The extension is defaulting to /usr/bin/python3, but I'm using the /usr/local/bin/ python install.

I don't see any docs on changing the path used by the extension for running shiny run. It would be helpful to have more docs on changing the extension settings.

For reference, my VS Code .devcontainer.json file:

{
    "name": "MY_APP",
    "build": {
        "dockerfile": "Dockerfile",
        "context": ".."
    },
    "extensions": [
        "github.copilot",
        "github.copilot-chat",
        "ms-python.python",
        "ms-azuretools.vscode-docker",
        "codezombiech.gitignore",
        "Gruntfuggly.todo-tree",
        "redhat.vscode-yaml",
        "george-alisson.html-preview-vscode",
        "posit.shiny-python"
    ],
    "settings": {
        "python.linting.enabled": true,
        "python.linting.pylintEnabled": true,
        "python.analysis.typeCheckingMode": "basic",
        "python.analysis.diagnosticSeverityOverrides": {
            "reportUnusedFunction": "none"
        }
    },
    "features": {
        "ghcr.io/devcontainers/features/docker-in-docker:2": {
        "version": "latest"
        }
    }
}

My dockerfile:

FROM python:3.9-slim

WORKDIR /app

RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    software-properties-common \
    git \
    libpq-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

COPY ../requirements.txt ./

RUN pip3 install -r requirements.txt

shiny extension not working

I have the shiny extension installed. But when I open an app.R, it does not load shiny extension. The "Run Source Code" button still sends the R code to radian console as any other R programme, and nothing happens. The app is not started. What do I need to do to get the shiny extension to come into play.

Extension ID renaming plan

In mid-May (when Joe gets back from vacation):

  • Publish new extension under Posit.shiny
    • Check version number in package.json
    • Update CHANGELOG.md
    • Ensure CHANGELOG.md version number is correct
    • Smoke test
    • Create release on GitHub with a vX.Y.Z tag, pasting in the changelog entries
    • Add .vsix to release artifacts
    • Blog/slack if appropriate
    • Close version milestone, reallocate issues if needed
    • After publish, increment version number
  • Simultaneously, publish new version of Posit.shiny-python that removes all contribution points and depends on Posit.shiny, and rename to "[Deprecated] ..."
    • Check version number in package.json
    • Update CHANGELOG.md
    • Ensure CHANGELOG.md version number is correct
    • Smoke test
    • Create release on GitHub with a vX.Y.Z tag, pasting in the changelog entries
    • Add .vsix to release artifacts
  • Unpublish the very old, long-deprecated rstudio.pyshiny so we don't have two deprecated extensions showing up in search
  • Review usage of Posit.shiny-python and PR the name change (e.g. Posit.shiny-python is a recommended extension in py-shiny)

Improve support for `ui.R` and friends style apps

Open the ui.R, server.R or global.R file of an Shiny for R app.

  1. The Run button modification isn't activated.
  2. Manually running the "Run Shiny app" command tries to run runApp("/full/app/path/ui.R"), which fails. It should be runApp("/full/app/path/").

Escaping for `cmd.exe` unnecessarily escapes parenthesis

The path escaping for cmd.exe turns

"C:\Program Files (x86)\R\R-4.3.3\bin\Rscript.exe"

into

"C:\Program Files ^(x86^)\R\R-4.3.3\bin\Rscript.exe"
#> The system cannot find the path specified.

Testing with Windows 11 via Parallels

Define path to R executable

Hello, for me it would useful if I could somehow define the path to the R executable on my machine instead of using the RPATH environment variable.

Would it be possible to do something similar to the Python version where it looks for the path definied in the Python Extension? Instead looking for the path definined in the R Extension using the following record in setting.json.
"r.rpath.windows":

run button does not work in Windows when python exe file in a path that contain space

when I hit run button,
This print out in terminal
C:\Program Files\Python310\python.exe -m shiny run --port 61780 --reload "c:\\Users\\user.name\\path\\app.py"

bash: C:Program: command not found
So there is a space in path C:\Program Files\ , thats the reason it is not working. But, by default my python exe file is there.
If I add quote manually in the python exe file path and run then that works.

'C:\Program Files\Python310\python.exe' -m shiny run --port 61780 --reload "c:\\Users\\user.name\\path\\app.py"

VSCode Extension not showing shiny run button

I am building Shiny Python apps with VSCode 1.74.3 and Python 3.10.9 in Windows 11. I have confirmed that shiny is installed and can be imported. I installed the Shiny extension for VS Code using version 0.0.3. I have created a file called app.py and copied the script for the basic app on your website. When I go to hit run by clicking the run icon in the top right, I am not presented with a choice to run a shiny app. When I try to run the app, the output in the terminal is simply python.exe c:/dir0/dir1/app.py and exits. No app is found at the 127.0.0.1:8000

Any ideas what might be missing? Thanks

Consider adding keyboard shortcut in VS Code extension to run shiny app

Thanks for the VS Code extension. It would be nice if there was a default keyboard shortcut to shiny.python.runApp. The shortcut could be the same as the render or preview Quarto extension shortcut ( Ctrl+Shift+K or Ctrl+Shift+L). Edit: I realized after posting that this issue should belong in the vscode extension repo which doesn't appear to be public at this time. Please close this issue if it is already being addressed.

Fail to load module script

I receive the following error in Chrome and VS Code Simple browser when trying to use input.textarea with autoresize=True.

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.

play button does not work with Conda environment

Can successfully run shiny from terminal but shiny play/run button in VScode does not seem to acknowledge the virtual environment.

running VScode on Mac Sonoma 14.2.1 with an M2 chip

(base) brendan@Brendans-Air distrodash % conda activate distrodash2
(distrodash2) brendan@Brendans-Air distrodash % /Users/brendan/anaconda3/bin/python -m shiny run --port 50911 --reload "/Users/brendan/Documents/GitHub/distrodash/shinypy/app.py"
/Users/brendan/anaconda3/bin/python: No module named shiny
(distrodash2) brendan@Brendans-Air distrodash % python -c "import shiny; print(shiny.__version__)"
 0.7.1
(distrodash2) brendan@Brendans-Air distrodash % /Users/brendan/anaconda3/bin/python -m shiny run --port 50911 --reload "/Users/brendan/Documents/GitHub/distrodash/shinypy/app.py"
/Users/brendan/anaconda3/bin/python: No module named shiny
(distrodash2) brendan@Brendans-Air distrodash % cd shinypy
(distrodash2) brendan@Brendans-Air shinypy % shiny run app.py
INFO:     Started server process [58637]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

v0.2.0 release checklist

  • Sign-off from QA
  • Check version number in package.json
  • Update CHANGELOG.md
  • Ensure CHANGELOG.md version number is correct
  • Smoke test
  • Create release on GitHub with a vX.Y.Z tag, pasting in the changelog entries
  • Add .vsix to release artifacts
  • Blog/slack if appropriate
  • Close version milestone, reallocate issues if needed
  • After publish, increment version number

Add command to run a packaged Shiny app as a gadget

This could be used to enable Shiny-based gadget apps that could be run as shortcuts. Here's a sketch of a shortcut to run the chattr R app.

    {
        "key": "cmd+k cmd+c",
        "command": "shiny.r.runApp.code",
		"name": "Chat with chattr",
        "args": {
            "langId": "r",
            "code": "chattr::chattr_app()"
        }
    },

The app would start up in a named terminal and the app would open in a simple browser window so that it could be moved around among the editor panes.

We should follow progress in posit-dev/positron#3173, if we can use multi-session support in Positron, that would improve the utility via hooks available in rstudioapi.

Add extension to the Open VSX Marketplace

RStudio Workbench VS Code users cannot install extensions from the Microsoft Marketplace. Instead, the extension browser searches the Open VSX Marketplace. We should publish the latest extension to Open VSX, so our pro customers can install the extension.

QA Testing of rc-v0.2.0

Two major features were added for rc-v0.2.0:

  1. #30
  2. #44

Follow-up issues found in this process:

  1. #52

Shiny for R apps

This feature brings support for running Shiny for R apps. The extension activates for R files named app.R, ui.R, server.R, global.R, app-*.R or *-app.R. Clicking the play button for such an app should run the app and preview it in the location determined by shiny.previewType (internal, external or none).

We need to check that this part of the extension works in the following environments:

  1. macOS
  2. Windows
    • For Windows, see the testing notes in #26, using a Shiny for R app in place of a Shiny for Python app.
    • Test in PowerShell, cmd.exe and Bash terminal environents.
  3. Linux
  4. GitHub Codespaces
  5. Posit Workbench

Shinylive

  • Test that we can share single-file and multiple-file apps to Shinylive. (See #44 for details).
  • Test that we can save single and multiple-file apps from Shinylive.
    • Single-file apps prompt users to pick a path to a file, e.g. examples/app.py. VS Code will prompt the user if they want to overwrite an existing file.
    • Multi-file apps prompt users to pick a non-existent directory.
  • Apps should roundtrip: create a shinylive link, choose to copy it, then save the app from the shinylive link.
  • Test hosts: both shinylive.io (released shiny) and posit-dev.github.io/shinylive (dev shiny)
  • Test output locations: open in browser and copy
  • Test modes: app or editor
  • The above settings can be fixed by choosing default values in the settings UI.

For the purposes of testing the extension, a Shinylive link is successfully created when opening the app in editor mode contains the same code as seen locally. There are many reasons why an app my fail to actually run in Shinylive; if the code and files you intended to send are indeed included in the editor, then the link was successfully created. Similarly, saving a Shinylive app locally should create files containing the expected code.

Allow port settings to take a range of ports

If port access is controlled in the environment running VS Code, users can set the port-related options to a fixed port to an allowed, open port. However, if the user has multiple VS Code instances open, they are limited to running one Shiny application at a time at the fixed port address.

We could update shiny.python.port, shiny.r.port and shiny.python.autoreloadPort to accept a range or array of ports:

"shiny.python.port": "8010-8020,8123",

The syntax could be {start}-{end} for start through end (inclusive) or comma separated values. The above would include ports 8010, 8011, ..., 8020, and 8123.

This would give system administrators the ability to open a limited range of ports, while allowing multiple apps to be run simultaneously.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.