The webR project is a version of the R interpreter built for WebAssembly.
Execute R code directly in a web browser, without a supporting R server. Alternatively, run an R process server-side using Node.js
π https://rconsortium.github.io/submissions-wg/
Create clinical trial submission deliverables with open-source software
Consists of Industry and Regulatory members
Pilot 3: Successful Shiny app submission to FDA reviewers
Now investigating containers and WebAssembly for Shiny app submission.
π Testing Containers and WebAssembly in Submissions to the FDA - pharmaverse.github.io
π Shiny Based Clinical Submissions - Eric Nantz posit::conf(2024)
Requires a reproducible workflow and software installation:
runApp()
, debugging.Install the Shinylive R package:
Convert the app:
Binary bundle ready to transfer to another machine or host on a static web service.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.
```{shinylive-r}
#| standalone: true
library(shiny)
# Create Shiny UI
ui <- [...]
# Create Shiny server function
server <- function(input, output, session) {
[...]
}
# Build Shiny app
shinyApp(ui = ui, server = server)
```
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit laborum.
#| standalone: true
#| viewerHeight: 700
library(shiny)
library(bslib)
theme <- bs_theme(font_scale = 1.5)
# Define UI for app that draws a histogram ----
ui <- page_sidebar(theme = theme,
sidebar = sidebar(open = "open",
numericInput("n", "Sample count", 50),
checkboxInput("pause", "Pause", FALSE),
),
plotOutput("plot", width=1100)
)
server <- function(input, output, session) {
data <- reactive({
input$resample
if (!isTRUE(input$pause)) {
invalidateLater(1000)
}
rnorm(input$n)
})
output$plot <- renderPlot({
hist(data(),
breaks = 30,
xlim = c(-2, 2),
ylim = c(0, 1),
xlab = "value",
freq = FALSE,
main = ""
)
x <- seq(from = -2, to = 2, length.out = 500)
y <- dnorm(x)
lines(x, y, lwd=1.5)
lwd <- 5
abline(v=0, col="red", lwd=lwd, lty=2)
abline(v=mean(data()), col="blue", lwd=lwd, lty=1)
legend(legend = c("Normal", "Mean", "Sample mean"),
col = c("black", "red", "blue"),
lty = c(1, 2, 1),
lwd = c(1, lwd, lwd),
x = 1,
y = 0.9
)
}, res=140)
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)
Binary R packages for WebAssembly are available from CRAN-like repositories
Over 65% of CRAN packages available for webR
π https://repo.r-wasm.org
R-Universe provides bioconductor, custom R packages
π https://r-universe.dev
Not all R packages work under WebAssembly.
Requires a web server, even for local applications.
There will always be good reasons to use a traditional Shiny deployment.
Browser security restrictions: limited networking & database access, no raw socket access.
https://webr.r-wasm.org/v0.4.2/
https://docs.r-wasm.org/webr/v0.4.2/