2

I'm trying to get a shiny app deployed on Shiny Server. I can do that without any issues, but when trying to deploy an app that has a number of dependencies (remote and local) we keep running into issues.

We used renv to track the dependencies (on the Windows dev box) and rebuild it from scratch on the Linux prod box, but even though the dependencies are rebuilt and some get loaded, others do not. The .Rprofile of the user running the app is pointing to the renv activation script.

For the sake of clarity, we need and want all the R code to be built from the source code on the Linux box.

What is the best or standard way (or even a poor way that works) to deploy the libraries for a shiny app to the shiny server? Is renv even the right tool for this scenario or is there a better tool?

I've tried reading the shiny server documentation and the closes it only mentions that it uses the .Rprofile of the user running the app, but there doesn't seem to be any sort of guide on the best way to deploy dependent libraries.

Player Two
  • 21
  • 2
  • "but even though the dependencies are rebuilt and some get loaded, others do not" -- can you expand on what you mean by that? Normally, calling renv::restore() should be enough to restore the library in whole. Can you elaborate a bit more on what you are doing, and what error(s) you are seeing? – Kevin Ushey Jun 18 '21 at 17:04
  • Hi, unfortunately I cannot. One dependency was not loaded for no valid reason everything looked fine (linked just like all the other libs), but still could not be loaded. I must've done something wrong as I wiped everything and got it working in the end. – Player Two Jun 20 '21 at 05:02
  • Good question! We are running shiny on CentOS. We have access to /srv/shiny-server/, but do not have privileges to install R packages in the default system library (/opt/R/4.1.0/lib/R/library on our system). – bdemarest Dec 14 '21 at 00:07

1 Answers1

1

This renv documentation discusses some reproducibility caveats:

  1. system dependencies, and
  2. changes in CRAN (e.g. a binary no longer being available).

Since you are moving from a Windows to a Linux system your packages may have unmet system dependencies (things that need to be installed outside of R) that you didn't encounter in Windows. For example, rJava is required for some of the Excel-related R packages, and getting its related system dependencies installed and working on Linux can sometime be a challenge. You can use the RStudio Package Manager Website to figure out what system dependencies are required for different R packages for your particular Linux OS. Also, the error messages you get when running these apps on Linux should point you in the right direction. These system dependencies are what you'll have to manage yourself since renv doesn't.

But for a more production-level solution you can try Docker and ShinyProxy. For apps with many dependencies or especially external dependencies (e.g. Python, SQL, etc.) you can guarantee more reproducibility using Docker. ShinyProxy can be used to host apps built into docker images. This is more work, but you ensure the entire system is reproducible, not just the R version and R packages. ShinyProxy also adds additional hosting capabilities like user authentication.

da11an
  • 701
  • 4
  • 8
  • The documentation is a bit "abstract" in my opinion. In the end I got it working to an acceptable degree (and yes RENV is very helpful in that regard), but my question was not about fixing the errors, but what's a good practice for deploying libs with Shiny Server. E.g. In the context of Shiny Server, the shared cache in RENV defaults to the current user directory, but is there a valid reason for this or should it be shared across the users used to run the app? There were a few other snags like this that I forget now - nothing unsolvable, but wished they were addressed in the docs. – Player Two Jun 20 '21 at 05:12
  • As a side note, I tried exploring docker on the free Azure layer, but the start-up performance was atrocious even for a hello world app (5 to +10 min). Do you have a better experience (on one of the higher tier Azure or AWS layers)? – Player Two Jun 20 '21 at 05:14
  • Hosting using shiny-server on an EC2 Linux instance on AWS gives reasonable performance. You can also add Rstudio-server to make it a nice cloud development/deployment hobby server. Might have needed swap space for that. Of course shinyapps.io is easy and free with decent performance for hobby stuff. – da11an Jun 22 '21 at 19:02