RConsortium / submissions-pilot4-webR

Development repository for Pilot 4 WebAssembly Shiny App
https://rconsortium.github.io/submissions-pilot4/
14 stars 5 forks source link
r shiny shinylive-r webassembly

Overview

Building upon the Submissions Pilot 2 in which a Shiny application created as an R package was successfully transferred to the FDA using the eCTD gateway protocol, the objective of Pilot 4 is to explore novel technologies to bundle the application along with the necessary execution dependencies and streamline the transfer and execution procedures. The specific technologies targeted in this pilot are the following:

This repository contains the WebAssembly version of the application.

Important Links

Development Setup

Package Environment

This application uses R version 4.4.1. Dependencies are managed by {renv} version 1.0.7. Once you have those installed on your system, you can restore the R package library by running renv::restore() in the R console.

Building and running the application

All supporting functions for building and running the application are contained in the utils.R script. Ensure that you load that in your R session with source("utils.R") before you proceed.

# build application
build_app()

This will compile the application into a new sub-directory _site by default. Note that this directory is not tracked in version control.

# run webassembly application
run_app_webassembly()

This will execute a server-side process in your R session and the application will be viewable on your local system. Open your local web browser and browse to this address: localhost:7654.

If you wish to run the application in the traditional method (with Shiny), you can run the following snippet:

# run traditional Shiny application
run_app_shiny()

Assembling ECTD bundle

To build a custom .zip archive of the application for eventual transfer in the ECTD gateway, run the following snippet:

# create application bundle zip archive
create_ectd_bundle()

By default a new file called r4app.zip will be created in the ectd_bundle sub-directory. Note that this bundle is not tracked in version control of this repository. Instead, a GitHub Action will automatically send this bundle to the Pilot 4 ECTD GitHub repository when the main branch of this repository is updated.

Alternative server process

While this repository positions R as the method for launching a local web server to run the application, other server options should also work. For example using Python from the command line:

# Navigate to the directory of the site deployment (_site by default)
# If Python version returned above is 3.X
# On Windows, try "python -m http.server" or "py -3 -m http.server"

python3 -m http.server 7654
# If Python version returned above is 2.X
python -m SimpleHTTPServer 7654

Open your local web browser and browse to this address: localhost:7654.

Automation

A set of GitHub actions have been created to automate the following processes:


webR compatibility limitations, issues and restrictions

Currently there are still some limitations when it comes to webR and {shinylive}.

Incompatible packages

Some packages used in the previous application versions are not available on CRAN. In adition to that, not all CRAN packages are compatible with webR itself. In the case of this project, that includes:

To circumvent this, non working dependencies and their functionality was either removed, replaced or shimmed. This includes:

Other notes


Generating a local version of the package dependencies (Experimental)

Currently there is no build in mechanism to serve packages locally, but we can tweak the exported version to allow this. After running build.R to generate the app, you can run build_offline_repo.R to download all the package files and replace the repo location. run this script after each successful build to update the output bundle.

NOTE: Currently a list of package files is stored in that file. These are collected manually by inspecting the browser network tab at run time. When adding new dependencies to the application those will need to be manually added on the script.

NOTE: After downloading the folder at least once it is advised to do a backup of its contents (100mb)

WARNING: This is a experimental work around. WebR will most likely support something similar by default.