| Title: | Run 'shiny' Applications in the Browser |
|---|---|
| Description: | Exporting 'shiny' applications with 'shinylive' allows you to run them entirely in a web browser, without the need for a separate R server. The traditional way of deploying 'shiny' applications involves a separate server and client: the server runs R and 'shiny', and clients connect via the web browser. When an application is deployed with 'shinylive', R and 'shiny' run in the web browser (via 'webR'): the browser is effectively both the client and server for the application. This allows for your 'shiny' application exported by 'shinylive' to be hosted by a static web server. |
| Authors: | Barret Schloerke [aut, cre] (ORCID: <https://orcid.org/0000-0001-9986-114X>), Winston Chang [aut] (ORCID: <https://orcid.org/0000-0002-1576-2126>), George Stagg [aut], Garrick Aden-Buie [aut] (ORCID: <https://orcid.org/0000-0002-7111-0077>), Posit Software, PBC [cph, fnd] (ROR: <https://ror.org/03wc8by49>) |
| Maintainer: | Barret Schloerke <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.5.0.9000 |
| Built: | 2026-11-25 23:40:56 UTC |
| Source: | https://github.com/posit-dev/r-shinylive |
Helper methods for managing shinylive assets.
assets_download( version = NULL, ..., dir = assets_cache_dir(), url = assets_bundle_url(version, dir = dir) ) assets_ensure( version = NULL, ..., dir = assets_cache_dir(), url = assets_bundle_url(version, dir = dir) ) assets_cleanup(..., keep = NULL, dir = assets_cache_dir()) assets_remove(versions, ..., dir = assets_cache_dir()) assets_info(quiet = FALSE) assets_version()assets_download( version = NULL, ..., dir = assets_cache_dir(), url = assets_bundle_url(version, dir = dir) ) assets_ensure( version = NULL, ..., dir = assets_cache_dir(), url = assets_bundle_url(version, dir = dir) ) assets_cleanup(..., keep = NULL, dir = assets_cache_dir()) assets_remove(versions, ..., dir = assets_cache_dir()) assets_info(quiet = FALSE) assets_version()
version |
The version of the assets: an exact version ( |
... |
Ignored. |
dir |
The asset cache directory. Unless testing, the default behavior should be used. |
url |
The URL of an assets tarball to download, such as a mirror.
When set, GitHub is never used: the version is chosen from the saved
release list and the downloaded assets. For a series or |
keep |
In |
versions |
The assets versions to remove. |
quiet |
In |
assets_version() returns the version of the currently supported Shinylive.
assets_download() invisibly returns the cache directory and
assets_ensure() invisibly returns the assets directory for version.
assets_cleanup() and assets_remove() return invisible().
assets_download(): Downloads the shinylive assets bundle from GitHub (or
url) and extracts it to the specified directory. The bundle will always be
downloaded from GitHub, even if it already exists in the cache directory
(dir=).
assets_ensure(): Ensures a local copy of shinylive is installed. If a local
copy of shinylive is not installed, it will be downloaded and installed.
If a local copy of shinylive is installed, its path will be returned.
assets_cleanup(): Removes local copies of shinylive web assets, except for
those matched by keep. Also removes temp files older than 10 minutes
that an interrupted download left in dir.
assets_remove(): Removes a local copies of shinylive web assets.
assets_info(): Prints information about the local shinylive assets that
have been installed. Returns a table of installed asset versions and their
associated paths, invisibly unless quiet = TRUE.
assets_version(): Returns the exact Shinylive assets version to use. It is
the newest release in the default series ("0.10.*"), checked on GitHub
at most once a day, or the highest downloaded version when offline. If
the SHINYLIVE_ASSETS_VERSION environment variable is set, it is used
instead (an exact version, a series, or "latest"). The result is
remembered for the R session and may download the assets.
Helper methods for testing updates to shinylive assets.
assets_install_copy( assets_repo_dir, ..., dir = assets_cache_dir(), version = package_json_version(assets_repo_dir) ) assets_install_link( assets_repo_dir, ..., dir = assets_cache_dir(), version = package_json_version(assets_repo_dir) )assets_install_copy( assets_repo_dir, ..., dir = assets_cache_dir(), version = package_json_version(assets_repo_dir) ) assets_install_link( assets_repo_dir, ..., dir = assets_cache_dir(), version = package_json_version(assets_repo_dir) )
assets_repo_dir |
The local repository directory for shinylive assets
(e.g. |
... |
Ignored. |
dir |
The asset cache directory. Unless testing, the default behavior should be used. |
version |
The version of the assets being installed. |
All method return invisible().
assets_install_copy(): Copies all shinylive assets from a local shinylive
repository (e.g.
posit-dev/shinylive). This
must be repeated for any change in the assets.
assets_install_link(): Creates a symlink of the local shinylive assets to the
cached assets directory. After the first installation, the assets will be the
same as the source due to the symlink.
assets_download(), assets_ensure(), assets_cleanup()
This function exports a Shiny app to a directory, which can then be served
using httpuv.
export( appdir, destdir, ..., subdir = "", quiet = getOption("shinylive.quiet", !is_interactive()), wasm_packages = NULL, package_cache = TRUE, max_filesize = NULL, assets_version = NULL, template_dir = NULL, template_params = list(), verbose = deprecated() )export( appdir, destdir, ..., subdir = "", quiet = getOption("shinylive.quiet", !is_interactive()), wasm_packages = NULL, package_cache = TRUE, max_filesize = NULL, assets_version = NULL, template_dir = NULL, template_params = list(), verbose = deprecated() )
appdir |
Directory containing the application. |
destdir |
Destination directory. Keep |
... |
Ignored |
subdir |
Subdirectory of |
quiet |
Suppress console output during export. Follows the global
|
wasm_packages |
Download and include binary WebAssembly packages as part
of the output app's static assets. Logical, defaults to The CRAN package |
package_cache |
Cache downloaded binary WebAssembly packages. Defaults
to |
max_filesize |
Maximum file size for bundling of WebAssembly package
assets. Parsed by |
assets_version |
The version of the Shinylive assets to use in the exported app. One of:
When |
template_dir |
Path to a custom template directory to use when exporting
the shinylive app. The template can be copied from the shinylive assets
using: |
template_params |
A list of parameters to pass to the template. The
supported parameters depends on the template being used. Custom templates
may support additional parameters (see With shinylive assets > 0.4.1, the default export template supports the following parameters:
|
verbose |
Nothing. The app is exported to destdir. Instructions for serving
the directory are printed to stdout.
app_dir <- system.file("examples", "01_hello", package = "shiny") out_dir <- tempfile("shinylive-export") # Export the app to a directory export(app_dir, out_dir) # Serve the exported directory if (require(httpuv)) { httpuv::runStaticServer(out_dir) }app_dir <- system.file("examples", "01_hello", package = "shiny") out_dir <- tempfile("shinylive-export") # Export the app to a directory export(app_dir, out_dir) # Serve the exported directory if (require(httpuv)) { httpuv::runStaticServer(out_dir) }
Integration with https://github.com/quarto-ext/shinylive
quarto_ext( args = commandArgs(trailingOnly = TRUE), ..., pretty = is_interactive(), con = "stdin" )quarto_ext( args = commandArgs(trailingOnly = TRUE), ..., pretty = is_interactive(), con = "stdin" )
args |
Command line arguments passed by the extension. See details for more information. |
... |
Ignored. |
pretty |
Whether to pretty print the JSON output. |
con |
File from which to take input. Default: |
Nothing. Values are printed to stdout.
The first argument must be "extension" (or "--version", which prints the
R package version). This is done to match
py-shinylive so that it can nest other sub-commands under the extension
argument to minimize the api clutter the user can see.
extension info
Prints information about the extension including:
version: The version of the R package
assets_version: The version of the web assets
scripts: A list of paths scripts that are used by the extension,
mainly codeblock-to-json
Example
{
"version": "0.1.0",
"assets_version": "0.2.0",
"scripts": {
"codeblock-to-json": "/<ASSETS_CACHE_DIR>/shinylive-0.2.0/scripts/codeblock-to-json.js"
}
}
extension base-htmldeps
Prints the language agnostic quarto html dependencies as a JSON array.
The first html dependency is the shinylive service workers.
The second html dependency is the shinylive base dependencies. This
dependency will contain the core shinylive asset scripts (JS files
automatically sourced), stylesheets (CSS files that are automatically
included), and resources (additional files that the JS and CSS files can
source).
Example
[
{
"name": "shinylive-serviceworker",
"version": "0.2.0",
"meta": { "shinylive:serviceworker_dir": "." },
"serviceworkers": [
{
"source": "/<ASSETS_CACHE_DIR>/shinylive-0.2.0/shinylive-sw.js",
"destination": "/shinylive-sw.js"
}
]
},
{
"name": "shinylive",
"version": "0.2.0",
"scripts": [{
"name": "shinylive/load-shinylive-sw.js",
"path": "/<ASSETS_CACHE_DIR>/shinylive-0.2.0/shinylive/load-shinylive-sw.js",
"attribs": { "type": "module" }
}],
"stylesheets": [{
"name": "shinylive/shinylive.css",
"path": "/<ASSETS_CACHE_DIR>/shinylive-0.2.0/shinylive/shinylive.css"
}],
"resources": [
{
"name": "shinylive/shinylive.js",
"path": "/<ASSETS_CACHE_DIR>/shinylive-0.2.0/shinylive/shinylive.js"
},
... # [ truncated ]
]
}
]
extension language-resources
Prints the language-specific resource files as JSON that should be added to the quarto html dependency.
For r-shinylive, this includes the webr resource files
For py-shinylive, this includes the pyodide and pyright resource files.
Example
[
{
"name": "shinylive/webr/esbuild.d.ts",
"path": "/<ASSETS_CACHE_DIR>/shinylive-0.2.0/shinylive/webr/esbuild.d.ts"
},
{
"name": "shinylive/webr/libRblas.so",
"path": "/<ASSETS_CACHE_DIR>/shinylive-0.2.0/shinylive/webr/libRblas.so"
},
... # [ truncated ]
]
extension app-resources
Prints app-specific resource files as JSON that should be added to the "shinylive" quarto html dependency.
Reads the app's files as JSON from con (stdin by default), downloads
WebAssembly binaries of the app's R packages, and prints those files and
their metadata.rds as resources.
Example
[
{
"name": "shinylive/webr/packages/metadata.rds",
"path": "/<QUARTO_PROJECT_DIR>/.quarto/_webr/destdir/shinylive/webr/packages/metadata.rds"
},
{
"name": "shinylive/webr/packages/brio/brio_1.1.5.tgz",
"path": "/<QUARTO_PROJECT_DIR>/.quarto/_webr/destdir/shinylive/webr/packages/brio/brio_1.1.5.tgz"
},
... # [ truncated ]
]