-
Notifications
You must be signed in to change notification settings - Fork 0
/
SharedRLibrary..Rmd
72 lines (53 loc) · 1.9 KB
/
SharedRLibrary..Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
title: "Shared R libraries"
author: "Paul Melloy"
date: "`r Sys.Date()`"
output: html_document
---
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.
```{bash eval=FALSE, echo=TRUE}
sudo mkdir /home/shared
```
Change the permissions on the shared folder to the user's group.
```{bash eval=FALSE, echo=TRUE}
#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
```
Check that 'shiny' and 'paul' are in the 'users' group, and add them if not
```{bash eval=FALSE, echo=TRUE}
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`
```{bash eval=FALSE, echo=TRUE}
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`
```{bash eval=FALSE, echo=TRUE}
echo "/home/shared/r_libs/" >> /home/paul/.Renviron
```
Then add the following to the top of a shiny `app.R` file.
```{r eval=FALSE, echo=TRUE}
.libPaths("/home/shared/r_libs/4.4/")
# Or
if(system("whoami") == "shiny"){
.libPaths("/home/shared/r_libs/4.4/")
}
```