Frequently when setting up a new virtual machine online to run a shiny server I run into issues that the shiny server can’t run because it can’t access the users library. The shiny server runs on the ‘shiny’ user and can’t access my ‘paul’ user R library.

There are many way to solve this, however one way is to have a shared library between me ‘paul’ and the ‘shiny’ user.

Log into the terminal in the background and create a new folder.

sudo mkdir /home/shared

Change the permissions on the shared folder to the user’s group.

#change group ownership to users
sudo chgrp users /home/shared 

# change permissions to drwxrwxr--
# the owner 'root' and group 'users' to read write execute and others read only
sudo chmod 774 /home/shared

# set group ids for and new subdirectories
sudo chmod +s /home/shared

# add an R library folder
mkdir /home/shared/r_libs/4.4

Check that ‘shiny’ and ‘paul’ are in the ‘users’ group, and add them if not

grep 'users' /etc/group

# add them if missing
sudo usermod -a -G users paul
sudo usermod -a -G users shiny

copy all ’paul’s libraries to shared/r_libs

cp -a /home/paul/R/x86_64-pc-linux-gnu-library/. /home/shared/r_libs/

While we could edit the system path variables in /usr/lib/R/etc/Renviron.site. I am not yet comforatble messing with the system variables, and this might interrupt additional users of the machine down the line.
Instead I will add the library to the user .Renviron

echo "/home/shared/r_libs/" >> /home/paul/.Renviron

Then add the following to the top of a shiny app.R file.

.libPaths("/home/shared/r_libs/4.4/")

# Or
if(system("whoami") == "shiny"){
  .libPaths("/home/shared/r_libs/4.4/")
}

Optional extra ubuntu / Debian packages needed for specific packages - libudunits2-dev - openssl -

sudo apt install libudunits2-dev openssl