| Title: | Seamlessly design robust 'shiny' extensions |
|---|---|
| Description: | 'charpente' eases the creation of 'shiny' extensions like 'shinydashboard', 'bs4Dash', 'shinyMobile'. It provides helpers to quickly set up a relevant package structure, import all external web dependencies (JavaScript, CSS) as well as initialize input/output bindings and custom handlers boilerplates. 'charpente' offers tools to convert HTML code into R to dramatically speed up the development of the template components as well as an high level interface to 'htmltools'. 'charpente' is a chatty package relying on the same principle as 'usethis' and more recently 'golem', that is make ('shiny') developer's life much easier. |
| Authors: | David Granjon [aut, cre], John Coene [aut], Alan Dipert [ctb] (Functions from html2r), Veerle van Leemput [ctb], RinteRface [cph], ThinkR [cph] (Some utils from golem) |
| Maintainer: | David Granjon <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.7.1 |
| Built: | 2026-05-28 08:57:51 UTC |
| Source: | https://github.com/RinteRface/charpente |
Generates a minified file under inst/pkg_name-pkg_version, if mode is prod. If mode is dev, aggregates all js files without mangling or compression.
build_js(dir = "srcjs", mode = c("prod", "dev"), entry_points = "main.js")build_js(dir = "srcjs", mode = c("prod", "dev"), entry_points = "main.js")
dir |
Default to srcjs. |
mode |
Production or development mode. Choose either "prod" or "dev". "prod" bundles, aggregates and minifyies files. "dev" only bundles the code. Modules follow the ES6 format (import/export). |
entry_points |
Entry point(s) to use in esbuild configuration. In case of a monolithic bundle, only one entrypoint is needed. This the default. In case of component based bundles, a vector of entrypoints is needed. The output files will match the entrypoints names. |
Configure charpente
charpente_options(local = TRUE)charpente_options(local = TRUE)
local |
Whether to download files locally or to point to a CDN. Default to TRUE. |
A list of options.
A charpente powered package does not differ from other package structure. create_charpente calls a series of function to help you quickly setting up the package structure.
create_charpente(path, remote = NULL, private = FALSE, license)create_charpente(path, remote = NULL, private = FALSE, license)
path |
A path. If it exists, it is used. If it does not exist, it is created, provided that the parent path exists. |
remote |
Name of the remote Github organization to connect to. |
private |
Whether the repository is private. Default to FALSE. |
license |
Which license is your project under? |
## Not run: create_charpente("bs4Dash") ## End(Not run)## Not run: create_charpente("bs4Dash") ## End(Not run)
Wrap internal scripts and stylesheets in one htmlDependency.
create_custom_dependency( name, version, entry_points, open = interactive(), mode )create_custom_dependency( name, version, entry_points, open = interactive(), mode )
name |
Package name. |
version |
Package version. |
entry_points |
Entry points to create dependency for. |
open |
Whether to allow rstudioapi to open the newly created script. Default to TRUE. |
mode |
Internal. Don't use. |
Download and create dependency function.
create_dependency( name, tag = NULL, open = interactive(), options = charpente_options() )create_dependency( name, tag = NULL, open = interactive(), options = charpente_options() )
name |
Name of library. |
tag |
Library version. Default to NULL. If NULL, takes the latest version. |
open |
Whether to allow rstudioapi to open the newly created script. Default to TRUE. |
options |
See charpente_options. |
## Not run: create_dependency("tabler") # Use CDNs create_dependency( "framework7", options = charpente_options(local = FALSE) ) ## End(Not run)## Not run: create_dependency("tabler") # Use CDNs create_dependency( "framework7", options = charpente_options(local = FALSE) ) ## End(Not run)
Creates a script in inst and the R part in ./R
create_input_binding( name, pkg = ".", dir = "srcjs", open = TRUE, initialize = FALSE, dev = FALSE, events = list(name = "click", rate_policy = FALSE), add_reference = TRUE ) create_output_binding( name, pkg = ".", dir = "srcjs", open = TRUE, add_reference = TRUE ) create_custom_handler( name, pkg = ".", dir = "srcjs", open = TRUE, add_reference = TRUE ) create_js( name, dir = "srcjs", open = TRUE, with_doc_ready = FALSE, template = golem::js_template, ..., add_reference = TRUE ) create_scss( name, dir = "styles", open = TRUE, template = golem::sass_template, ..., add_reference = TRUE )create_input_binding( name, pkg = ".", dir = "srcjs", open = TRUE, initialize = FALSE, dev = FALSE, events = list(name = "click", rate_policy = FALSE), add_reference = TRUE ) create_output_binding( name, pkg = ".", dir = "srcjs", open = TRUE, add_reference = TRUE ) create_custom_handler( name, pkg = ".", dir = "srcjs", open = TRUE, add_reference = TRUE ) create_js( name, dir = "srcjs", open = TRUE, with_doc_ready = FALSE, template = golem::js_template, ..., add_reference = TRUE ) create_scss( name, dir = "styles", open = TRUE, template = golem::sass_template, ..., add_reference = TRUE )
name |
The name of the module. |
pkg |
Path to the root of the package. Default is |
dir |
Path to the dir where the file while be created. |
open |
Should the created file be opened? |
initialize |
For JS file - Whether to add the initialize method. Default to FALSE. Some JavaScript API require to initialize components before using them. |
dev |
Whether to insert console.log calls in the most important methods of the binding. This is only to help building the input binding. Default is FALSE. |
events |
List of events to generate event listeners in the subscribe method.
For instance, |
add_reference |
Whether to add an import statement in main.js. Defaults to TRUE. |
with_doc_ready |
For JS file - Should the default file include |
template |
Function writing in the created file. You may overwrite this with your own template function. |
... |
Arguments to be passed to the |
This is a central piece if you want to have your app standalone for instance
create_manifest( path, name = "My Progressive Web App", shortName = "My App", description = "What it does!", lang = "en-US", startUrl = "/", display = c("standalone", "minimal-ui", "fullscreen", "browser"), background_color = "#ffffff", theme_color = "#ffffff" )create_manifest( path, name = "My Progressive Web App", shortName = "My App", description = "What it does!", lang = "en-US", startUrl = "/", display = c("standalone", "minimal-ui", "fullscreen", "browser"), background_color = "#ffffff", theme_color = "#ffffff" )
path |
App path. |
name |
App name. |
shortName |
App short name. |
description |
App description |
lang |
App language (en-US by default). |
startUrl |
Page to open at start. |
display |
Display mode. Choose among |
background_color |
The background_color property is used on the splash screen when the application is first launched. |
theme_color |
The theme_color sets the color of the tool bar, and may be reflected in the app's preview in task switchers. |
This function creates a www folder for your shiny app. Must specify the path. It creates 1 folders to contain icons and the manifest.json file.
See https://developer.mozilla.org/en-US/docs/Web/Manifest for more informations.
create_manifest( path = tempdir(), name = "My App", shortName = "My App", description = "What it does!", lang = "en-US", startUrl = "https://www.google.com/", display = "standalone", background_color = "#3367D6", theme_color = "#3367D6" )create_manifest( path = tempdir(), name = "My App", shortName = "My App", description = "What it does!", lang = "en-US", startUrl = "https://www.google.com/", display = "standalone", background_color = "#3367D6", theme_color = "#3367D6" )
List all relevant pwa resources in a custom dependency. Includes the web manifest + icons using the head parameter of htmltools::htmlDependency.
create_pwa_dependency(open = interactive())create_pwa_dependency(open = interactive())
open |
Whether to allow rstudioapi to open the newly created script. Default to TRUE. |
Query from https://data.jsdelivr.com/v1/package/npm/ under the hood.
get_dependency_assets(dep, tag = "latest")get_dependency_assets(dep, tag = "latest")
dep |
Library name. |
tag |
Library version. Default to latest. |
A list of url containing links to CSS and JS dependencies for the given library.
## Not run: get_dependency_assets("bootstrap") get_dependency_assets("framework7", tag = "5.5.5") ## End(Not run)## Not run: get_dependency_assets("bootstrap") get_dependency_assets("framework7", tag = "5.5.5") ## End(Not run)
Query from https://data.jsdelivr.com/v1/package/npm/ under the hood.
get_dependency_versions(dep, latest = FALSE)get_dependency_versions(dep, latest = FALSE)
dep |
Library name. |
latest |
Whether to get the last version. Default to FALSE. |
A vector containing all versions
## Not run: get_dependency_versions("framework7") get_dependency_versions("bootstrap") get_dependency_versions("react", latest = TRUE) ## End(Not run)## Not run: get_dependency_versions("framework7") get_dependency_versions("bootstrap") get_dependency_versions("react", latest = TRUE) ## End(Not run)
Used by update_dependency.
get_installed_dependency(name)get_installed_dependency(name)
name |
Library name |
A character containing the version number
Retrieves Package Name
get_pkg_name()get_pkg_name()
Name of package.
Convert HTML content to R Shiny tags
html_2_R(html, path = "/html/body/*", prefix = TRUE)html_2_R(html, path = "/html/body/*", prefix = TRUE)
html |
HTML string |
path |
Path where to extract elements. Default to body content. |
prefix |
Whether to prefix elements by tag$... |
A list of R Shiny tags
Alan Dipert, RStudio
if (interactive()) { library(charpente) bs4_card <- '<div class="card" style="width: 18rem;"> <img class="card-img-top" src="..." alt="Card image cap"> <div class="card-body"> <h5 class="card-title">Card title</h5> <p class="card-text">Some quick example text.</p> <a href="#" class="btn btn-primary">Go somewhere</a> </div> </div>' html_2_R(bs4_card) ## With non standard attributes tag <- "<div data-toggle='accordion'></div>" html_2_R(tag) }if (interactive()) { library(charpente) bs4_card <- '<div class="card" style="width: 18rem;"> <img class="card-img-top" src="..." alt="Card image cap"> <div class="card-body"> <h5 class="card-title">Card title</h5> <p class="card-text">Some quick example text.</p> <a href="#" class="btn btn-primary">Go somewhere</a> </div> </div>' html_2_R(bs4_card) ## With non standard attributes tag <- "<div data-toggle='accordion'></div>" html_2_R(tag) }
Installs esbuild for the local project
set_esbuild(light = FALSE)set_esbuild(light = FALSE)
light |
Used to only install Sass plugins. This is to workaround a breaking change in charpente where styles does not exist in old versions. |
Installs esbuild in node_modules (dev scope), if not existing, creates srcjs + srcjs/main.js andstyles + styles/main.scss, and sets relevant files and folders in .gitignore. and .Rbuildignore.
Installs mocha for the local project
set_mocha()set_mocha()
Installs mocha in node_modules (dev scope), creates srcjs/test folder, write basic test im test_basic.js
Creates a web manifest, service-worker.js, icons and set the necessary dependencies. The app must be part of a package. Must not be used from the package root but from the app root.
set_pwa( path, name = "My Progressive Web App", shortName = "My App", description = "What it does!", lang = "en-US", startUrl = "/", display = c("standalone", "minimal-ui", "fullscreen", "browser"), background_color = "#ffffff", theme_color = "#ffffff", register_service_worker = TRUE, create_dependencies = TRUE )set_pwa( path, name = "My Progressive Web App", shortName = "My App", description = "What it does!", lang = "en-US", startUrl = "/", display = c("standalone", "minimal-ui", "fullscreen", "browser"), background_color = "#ffffff", theme_color = "#ffffff", register_service_worker = TRUE, create_dependencies = TRUE )
path |
App path. |
name |
App name. |
shortName |
App short name. |
description |
App description |
lang |
App language (en-US by default). |
startUrl |
Page to open at start. |
display |
Display mode. Choose among |
background_color |
The background_color property is used on the splash screen when the application is first launched. |
theme_color |
The theme_color sets the color of the tool bar, and may be reflected in the app's preview in task switchers. |
register_service_worker |
Whether to register the service worker. Default to TRUE. Don't change the file name of service-worker.js!!! |
create_dependencies |
Default to TRUE. Relevant if used in a shinyMobile context. If used outside, you must set it to FALSE and handle the dependencies yourself. |
Test the entire srcjs/test folder
test_js()test_js()
A message showing the test results
Update the given dependency to a specific version or latest
update_dependency(name, version_target = "latest")update_dependency(name, version_target = "latest")
name |
Library name. |
version_target |
Targeted version. Default to latest. |
## Not run: update_dependency("framework7") ## End(Not run)## Not run: update_dependency("framework7") ## End(Not run)