RShiny is an increasingly popular package for the R programming language. It can be used to easily develop interactive web applets, and as such it is a con- venient tool for creating browser-based companions to presentations, thesis and publications. In this article, the GWDG server for hosting RShiny apps is introduced, as well as the basics of creating an app.
RSHINY HOSTING AT THE GWDG
RShiny is a package for the programming language R, whcih makes it easy to develop and deploy interactive browser-based applets. As such, it is ideal as an interactable multimedia compa- nion piece to publications. Since 2022, the GWDG has offered a server for hosting RShiny apps at [1]. The server is hosted on a vir- tual machine (VM), with an 8-core 2.9 GHz CPU and around 60 GB of RAM. Utilizing a VM allows for the server to be easily scaled up and down to meet the demands of the hosted applications. For example, one of our currently hosted apps requires a database of several GBs of size be loaded in memory at all times. Increasing the server’s RAM to accomodate this requirement was a simp- le and straightforward process. Additionally, virtualization makes it easier to recover from system problems, and minimizes hardware- related issues. With some previous setup, it is also possible to access the interactive GPU queue of the GWDG’s Scientific Com- pute Cluster (SCC), providing GPU capabilities at all times.
Currently five apps are being hosted on the website (see Figu- re 1), alongside a couple of example and test applications. All of these apps are associated with publications, with some providing interactive visualizations of the contents of their publications, and others implementing tools and models that can analyze user provi- ded data and return results. A particular highlight is the app named CLARUS (see Figure 2) provided by Beinecke, Saranti, et al. (pre- publication: [2]), a collaborative effort between a number of resear- chers and programmers that implements platform for interactively manipulating graph neural networks (GNNs) to make them “exp- lainable”, and presents patient related data as an applied example. The RShiny application is in fact only one half of a frontend/ backend setup, with the backend (where the bulk of the calculati- ons are performed) consisting of a Python-Flask server used for communication with the frontend, and using Pytorch and GPUs for the machine learning part, hosted on the interactive GPU queue of our SCC. This GPU setup solves the problem of always having a GPU available for end users that might access the application, but at the same time not needing to provide and maintain an expensi- ve GPU that might idle a large percentage of the time just for the RShiny server. Hosting the app on our servers involved a process of iterative feedback with the apps’s authors, to overcome some limitations and implement features such as batch processing of data in the backend. The frontend itself, making use of RShiny, is also quite complex, offering the posibility of loading different datasets, manipulating and retraining the GNN, offering various visualization possibilities, and downloading results.
Although there are other public hosts available for RShiny applications as well as the possibility of self-hosting, we offer a number of advantages over these other services: no extra or ongo- ing charges (beyond those already present in the service agree- ment between your institution and the GWDG), access to the con- sultation with our admins and their expertise, and access to our HPC resources (VM and GPUs through the SCC).
We are always looking for new apps to host. If you are interested in this service, pelase contact us. We require the code for the app be hosted in some version control repository (for example, our own gitlab instance at [3]). The goal is to host more or less completed apps (that is, the app should be in its final stages, and we can help with refining the last few steps of the app), which need to be hosted for longer periods of time (for example, associa- ted with a publication or thesis or other long term projects). One of our admins will set the app up on the server, check back with you and provide any necessary feedback, and eventually make the app “public” on the landing page at [1].
INTRO TO RSHINY APPS
The R programming language forms the basis for RShiny apps. R is an interpreted, functional, object oriented, strong and dynamically typed language. It posesses a robust suite of user generated packages, particularly in the fields of statistics, visuali- zation, and bioinformatics. Advanced integrated development envi- ronments (IDEs) are available for R, such as RStudio and Jupyter, and the GWDG provides servers for both of these IDEs. If you have experience in programming languages with similar features such as Python, it is rather easy to pick up. Additionally, for those more comfortable with Python, there is a “Shiny for Python“ libra- ry being developed and already available in alpha status [4].
All the requirements for developing RShiny apps can be installed easily in your local machine and apps tested locally on your own browser. RShiny development can also be tested on our RStudio server [5] without the need for installing any extra soft- ware. Do note that to access the RStudio server, HPC/SCC access is previously required.
Here follow some basics and examples of how an RShiny app is set up. For some more information and useful links, please also refer to the GöHPCoffee presentation from 03.08.2022 at [6].
Basic Setup of an App
An app in RShiny is divided into an ui (“user interface”) and ser- ver sections. At the basic level, both can be built by stacking sim- ple RShiny elements without the need for much more R program- ming. The ui includes all objects the user can interact with, from sli- ders and tick boxes to text displays and plots. The server defines what happens when the user interacts with the ui portion of the app, that is, it does all the processing behind the scenes. The server references objects in the ui directly, and can update output objects (i.e. plots) in response to changes in input objects (i.e. user input). An example of this setup is provided in Figure 3, based on one of the sample apps provided by the RShiny package. In this case, the ui defines and gives specific names to two object, a slider which is associated with the variable “bins”, and a histogram plot which is assigned the ID “distPlot”. When the user interacts with the slider, the server is informed of the change to the bins variab- le, executes its code again, and remakes the histogram plot. This stacking and interacting of simple ui and output objects can alrea- dy create complex apps, as we will see in the following section.
Example App: Portfolio Simulation
As an example application, we present an interactive “simu- lation” of the evolution of an investment portfolio using historical stock market returns. The app and its code can be found at [7], and the GUI of the app is shown in Figure 4. This app is a useful show- case of RShiny’s features, since we have a number of clear inputs for our end-user to manipulate (length of withdrawal from the port- folio, starting capital, capital drawdown per year, number of simu- lations, etc.), a simple but tedious computational task (the simula- tion of the portfolio’s progress according to various historical mar- ket returns), and data that benefits from being presented graphi- cally (the evolution of the various individual simulations, as well as various ways of displaying their final status).
The implementation is rather straightforward: on the ui side, we set up various sliders and checkboxes to allow the user to input the simulation’s parameters; while on the server side, we just need to implement the portfolio calculations based on the parameters obtained from the ui side, and present the results to the user in a number of plots and text outputs. Some accessory code serves to load up the historical market performances and prepare them for the following calculations.
This app is a good test ground to practice R and RShiny. Some ideas for further development would be to allow the user to down- load their generated plots and results as a CSV file, allowing the user to upload their own market data, including more complicated portfolios such as bonds, implementing a “Simulate” button so processing is delayed until user has finished inputing parameters, improving the plots, etc.
FUTURE OF RSHINY AT ThE GWDG
We believe RShiny is a valuable service for us to provide at the GWDG. Beyond hosting more applications we are looking into expanding our related offers according to the community’s inte- rest level. One possibility is to offer an RShiny workshop, starting with the basics of R and designing an app and moving on to more complex topics such as back- and front end setups, ending with the attendeees developing and presenting their own applications. As for the RShiny host itself, we want to offer access stats for each application, and so enable researchers to gauge interest in their code.
For further updates, please join the bioinformatics mailing list [8] and Rocket.Chat channel [9].
LINKS
[2] https://www.biorxiv.org/content/10.1101/2022.11.21.517358v1
[4] https://shiny.rstudio.com/py/
[7] https://rshiny.gwdg.de/apps/sample-apps/portfolio_sim/
[8] https://listserv.gwdg.de/mailman/listinfo/hpc-in-lifescience
[9] https://chat.gwdg.de/channel/bioinformatics