Skip to main content

Managing assets and Deployment

Loading local / online resources#

There are three headers for loading local / online resources, namely the load_library, load_script and load_data.

  • load_library is for loading modules supported by this package and from a curated set of JavaScript libraries. At the time of writing, it supports

    • JavaScript libraries: mathjs, tensorflow, p5, chart, plotly, d3, vegalite, ramda,
    • styling libraries: fontawesome, ionicons, tailwind, and
    • modules: dom, io, websocket and testthat.
  • load_script is for loading JavaScript / CSS stylesheets from online links (use with care) or local files.

  • load_data is for loading local data (e.g. CSV and JSON files).

In general, online resources are embedded as links, while local resources are embedded using data URI scheme.

Deployment#

Depending on the use case, there are a few ways to share / deploy your application.

Deploy the source files#

The easiest way to share is to share your source R files. This allows your user to examine and modify the application, but it requires them to have R and sketch installed. If the R file is a single-script application, others can even use load_script to access the file via a link should you host it online.

Deploy the HTML file#

The second way to deploy is to share the HTML file generated by sketch.

To get the HTML file, note that when the source_r function is run, it returns invisibly the temporary path of the HTML file it generates. One can use the R command file.copy to copy the file to the working directory and share that file with others.

The advantage of deploying an HTML file is that it does not require R installation, and it can be deployed to anywhere that serves static websites (e.g. Github, Netlify).

By default, all local resources you use are embedded into the HTML file, so it is sufficient to share only the HTML file instead of sending over a file with a folder of assets attached.

If you need the application to work offline, you could use the R command download.file to save the online resources into files and call load_script on the local files instead of the online links. This makes the HTML file completely self-contained (with a larger file size).

Deploy the JavaScript file#

If you are developing a library or some general utility functions, you can call compile_r to turn R files into JavaScript files, instead of calling source_r which generates and wraps everything into an HTML.

Then you can deploy the JavaScript files online (e.g. NPM, Github) and take advantage of CDN services like jsdelivr.

Deploy as a binary#

For users who are looking to develop standalone mobile / desktop / server applications, which are considered as stretched goals of this package, it is recommended to look into Progressive Web App, Electron JS and Deno (see Deno v1.6 release note in particular). They are all developed for JavaScript, and they help users set up the necessary infrastructure to achieve portability to the desired platforms.