Shortly before we finished the first manuscript of our paper “A Comparison of Statistical Methods for Time-To-Event Analyses in Randomized Controlled Trials Under Non-Proportional Hazards”, the first version of shinylive for R was released. I had already written a shiny-app to interactively browse the scenarios and simulation results of our simulation study. This shiny app was hosted at Medical University of Vienna with some limitations on availability and some maintenance overhead.
The presentation of the results of a simulation study are the ideal candidate to port the app to shinylive. The data are entirely public and also don’t change after publication, so no server is needed to update the data or limit access to users. The shinylive app can be hosted as static files on github pages (or anywhere), with high availability and very little maintenance.
So, despite the project of shinylive being quite young I ported our app to shinylive. Here are some of the experiences I made.
Interactivity
While web-r is slower than native R. While the speed of one-off computations is easily fast enough triggering computations on every change of every UI element was too slow and led to ferquent freezes. The cleanest option to avoid this would have probably been to use debounce. But since I suspected that debouncing could require some fine-tuning for the timeout and also give inconsistent results in different browsers, I went for the even simpler solution to just add a button that triggers the does the calculations and re-draws the plots once all settings are input.
Packages
In the beginning the availability of packages for web-r was mixed. The most annoying thing was that some packages that were source packages or compiled for web-r had strong dependencies on unavailable packages only for functionality I did not use.
While all necessary packages became available eventually, this had (has?) another downside, it slows down loading of the app. In the earliest versions the shinylive page just included web-r and the javascript necessary to start shiny in the web-r session and all packages were installed into the web-r session. This meant not only loading the packages one needs but also the whole documentation, example data sets unneeded dependencies, etc. from the repository. The possibility to bundle packages and serve them together with the shinylive app was added in one of the first larger updates but the mechanism to install the package in the web-r session stayed the same, it was just loaded from somewhere else. Web-r has added support for wasm virtual file systems. When client and server support this only parts of the file-system that are used have to be transfered. With this it would be possible to pre-install packages in the virtual file system and not install but just load them during app start, removing quite some overhead. Last time I updated the app this feature was not used in shinylive. I hope this feature will be added (or is already added) to shinylive.
Compataibility
Browser compatibility was very limited, the last time I checked. In Chrome based browsers the app worked in a usable speed – about one second to draw a plot – but on Firefox it took about ten times as long, not really usable interactively. On Safari the app didn’t work at all. While I found some bugreports in web-r, Firefox and shinylive that could relate to the issue I was not able to pin down the issues and fix them. I hope they will be fixed in subsequent versions of all the involved software.
Final product
So what did I acutally build?
Here’s the app for the simulation results presented in the paper, and here’s the app presenting the simulation results of different scenarios I simulated for my masters thesis. Sourcecode for both can be found on github here and here.