We’re excited to announce the new Shiny extension for VS Code! Along with a new name, the Shiny extension now supports running both Shiny for R and Shiny for Python apps!
When we introduced the Shiny for Python VS Code extension, its name made a lot of sense: the extension helped Shiny for Python developers run their apps in VS Code. But with the latest v1.0.0 release, we’ve expanded the extension to support running Shiny for R apps – as well as a few new features for moving between local files and ShinyLive links – and we wanted a name that reflected that. In this post, we’ll talk through the new features and show you how to use them.
Installing the Shiny extension
If you’re a new Shiny + VS Code user, you can install the extension from the VS Code Marketplace or the Open VSX Registry, or by searching for “Shiny” in the Extensions view in VS Code. Be sure to avoid the extension named “Shiny (deprecated)” 😉
If you’re already using the Shiny for Python extension, you can simply update the old extension to kick off a seamless transition in which the new extension will be automatically installed. Once installed, the new extension will prompt you to uninstall the older version.
Shiny for R Support
With the Shiny extension installed, whenever you open an app.R
file — or another appropriately named Shiny for R app file1 — the editor’s play button () becomes a “Run Shiny App” button. Clicking the starts your app in a new terminal session and even enables Shiny’s developer mode for a better local development experience, including automatically restarting your app when you update and save the app’s source files2.
ShinyLive
ShinyLive is a free service for sharing Shiny apps via static hosting, where Shiny apps run entirely in the browser without the need for a server. Head to shinylive.io/py or shinylive.io/r to get started with the language of your choice. When your app is ready, share the ShinyLive link with others for instant deployment!
While ShinyLive features an online editor (for R or Python), sometimes you might want to create a ShinyLive link from files you’re editing in your IDE. The Shiny extension now gives you two ways to do this.
Create a ShinyLive link from the active file
For single-file apps, run the Create ShinyLive Link from Active File from the command palette with an app.py
or app.R
open and active in the editor.
Create a ShinyLive link from multiple files
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.
After picking your file(s) for the ShinyLive link, 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.
Save the app from a ShinyLive link
You can also create local files from a ShinyLive link using the Save App from ShinyLive Link command in the command palette. You’ll be prompted to paste the ShinyLive link and then to choose where the app will be saved in your workspace.
New snippets and settings
Snippets in VS Code are templates of reusable code accessible via the Insert snippet command in the Command Palette or as a tab-completion when you type out the snippet trigger text. The Shiny extension includes three text snippets to help you quickly create a Shiny app or Shiny module:
shinyapp
creates a new Shiny application templateshinymod
creates a new Shiny module templateshinyexpress
creates a new Shiny Express app template (in Python)
We’ve also expanded the settings available to the Shiny extension. Most notably, the added shiny.previewType
setting determines whether the app preview is opened inside VS Code (internal
), in an external
browser, or not at all (none
). A number of ShinyLive settings allow you to choose default values to speed up link creation. The full list of extension settings are available in the extension page in VS Code or in the extension repository.
Thanks!
Thank you for trying out the Shiny extension for VS Code! If you find it helpful, please rate the extension on the marketplace or the open-vsx registry.
Footnotes
A valid Shiny for R app is an R file that includes the word “shiny” in its contents and is named
app.R
,ui.R
,server.R
, or has a name that starts or ends withapp
.↩︎Developer mode enables a few Shiny options that improve the local development experience and can be turned on at the R console by calling
shiny::devmode()
. Notable among these options is settingoptions(shiny.autoreload = TRUE)
to automatically reload the app whenever its source files change. An extension setting can be used to disable devmode.↩︎