R - How to set the path of install.packages() for shiny server ? - Ubuntu
Asked Answered
P

3

5

For my system: Ubuntu 12.04 and R 3.03, whenever I install a custom package in R via

>install.packages()

the package is installed by default to

/home/USER/R/x86_64-pc-linus-gnu-library/3.0/ 

as opposed to system-wide in

/usr/local/lib/R/site-library/

which is needed for shiny-server to work with that package.

My temporary solution is to copy the packages to the correct folder after the fact.

Question: How can I set the default install path from the start to avoid this problem?

Pascia answered 28/3, 2014 at 3:24 Comment(3)
Easiest way is usually to login as root (sudo -i), open R, and install it there. Then the package will be site-wide.Abortion
Not sure I can that easiest :)Devilry
// , Do you think this is relevant to #42048190Ragi
D
4

Yes -- I consider this to be a misfeature and disable my per-user directory.

Moreover, I mostly use a script install.r (of which a version is an example in the littler package you can install as part of Ubuntu) which simple explicitly set the /usr/local/lib/R/site-library directory as the default. With a patch we got into R 3.0.2 or 3.0.3, normal user can write into the directory and will now create group-writeable directories so other users can update and overwrite -- just make everybody a member of the same group, say staff or admin. And then you don't even need sudo or root.

I have essentially answered this same question a few times here over the years (minus the shiny angle, which is not really relevant) so feel free to search for the other for more details, examples, ...

Devilry answered 28/3, 2014 at 3:45 Comment(1)
Thanks, I can figure it out from there. I'll look again for a similar question - I had no luck on my first bunch of searches for it.Pascia
G
0

I would propose a different approach.

The problem is that shiny-server cannot find the packages that you install because it runs them as a different user which is called shiny. This user is created upon installation of shiny-server

The easiest (and safest IMHO) way to solve this is to just install the packages as the shiny user, using the following steps.

  1. Set a password for the user using sudo passwd shiny, now enter and confirm a password of your choosing.
  2. Switch to the shiny account using: su - shiny
  3. Call up R using $ R (without sudo)
  4. Install the required packages, in this case: `install.packages("shinydashboard")

Note that if you have rstudio-server installed on the same machine then you can perform steps 2-4 using that interface. Simply go the same domain/ip and use :8787 for the rstudio-server interface instead of :3838 for shiny-server.

Adapted from my answer here

Goolsby answered 7/10, 2015 at 15:46 Comment(2)
I cannot login using shiny account in the R studio server terminal. I did set password.Laud
yeah I cannot seem to login either since a certain version. I have not idea what the problem is with thatGoolsby
L
0

Offering another solution, and that is to specify the user library as the location rather than the shiny library which uses the /usr/local/lib/R/site-library library location to your user name.

In bash open the shiny-server configuration file

sudo nano /etc/shiny-server/shiny-server.conf

Then change the run_as from the shiny user to your own username soran

# Define the user we should use when spawning R Shiny processes
#run_as shiny; # old line
run_as soran;

# Define a top-level server which will listen on a port
server {
  # Instruct this server to listen on port 3838
  listen 3838;
....

After changing the file stop the server and start it again so the new configuration is loaded.

sudo systemctl stop shiny-server
sudo systemctl start shiny-server

This will change all shiny apps served by your server to use the users R library. I would also recommend not using a user with admin or root privileges for security.

It is possible to only specify the users R library to specific applications. To do this you need to specify certain shiny app subdirectories to load under that users r profile by using run_as with the subdirectory name in location. See the following documentation for more details.

https://docs.posit.co/shiny-server/#stopping-and-starting

Lunnete answered 10/5 at 4:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.