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 in 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] , Winston Chang [aut] , George Stagg [aut], Garrick Aden-Buie [aut] , Posit Software, PBC [cph, fnd] |
Maintainer: | Barret Schloerke <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.0.9000 |
Built: | 2024-11-13 17:20:07 UTC |
Source: | https://github.com/posit-dev/r-shinylive |
Helper methods for managing shinylive assets.
assets_download( version = assets_version(), ..., dir = assets_cache_dir(), url = assets_bundle_url(version) ) assets_ensure( version = assets_version(), ..., dir = assets_cache_dir(), url = assets_bundle_url(version) ) assets_cleanup(..., dir = assets_cache_dir()) assets_remove(versions, ..., dir = assets_cache_dir()) assets_info(quiet = FALSE) assets_version()
assets_download( version = assets_version(), ..., dir = assets_cache_dir(), url = assets_bundle_url(version) ) assets_ensure( version = assets_version(), ..., dir = assets_cache_dir(), url = assets_bundle_url(version) ) assets_cleanup(..., dir = assets_cache_dir()) assets_remove(versions, ..., dir = assets_cache_dir()) assets_info(quiet = FALSE) assets_version()
version |
The version of the assets to download. |
... |
Ignored. |
dir |
The asset cache directory. Unless testing, the default behavior should be used. |
url |
The URL to download the assets from. Unless testing, the default behavior should be used. |
versions |
The assets versions to remove. |
quiet |
In |
assets_version()
returns the version of the currently supported Shinylive.
All other methods return invisible()
.
assets_download()
: Downloads the shinylive assets bundle from GitHub 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
the one used by the current version of shinylive.
assets_remove()
: Removes a local copies of shinylive web assets.
assets_info()
: Prints information about the local shinylive assets that
have been installed. Invisibly returns a table of installed asset versions
and their associated paths.
assets_version()
: Returns the version of the currently supported Shinylive
assets version. If the SHINYLIVE_ASSETS_VERSION
environment variable is set,
that value will be used.
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 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 = NULL )
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 = NULL )
appdir |
Directory containing the application. |
destdir |
Destination directory. |
... |
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 |
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. Defaults to |
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 |
Deprecated, please use |
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"
. 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.
Currently, r-shinylive does not return any resource files.
Example
[ { "name": "shinylive/pyodide/anyio-3.7.0-py3-none-any.whl", "path": "/<ASSETS_CACHE_DIR>/shinylive-0.2.0/shinylive/pyodide/anyio-3.7.0-py3-none-any.whl" }, { "name": "shinylive/pyodide/appdirs-1.4.4-py2.py3-none-any.whl", "path": "/<ASSETS_CACHE_DIR>/shinylive-0.2.0/shinylive/pyodide/appdirs-1.4.4-py2.py3-none-any.whl" }, ... # [ truncated ] ]