0

Problem

I'm deploying a Shiny App on a shiny server maintained by my university, and there are many .libPaths() that contain different versions of packages.

> .libPaths()
[1] "/zeolite/rpauloo/R/x86_64-pc-linux-gnu-library/3.4"
[2] "/nfs/admin/software/xenial/system-gcc/R_libs"      
[3] "/usr/local/lib/R/site-library"                     
[4] "/usr/lib/R/site-library"                           
[5] "/usr/lib/R/library"  

When my shiny app boots up, shiny is loaded by default from .libPaths()[2], which then imports R6 V.2.2.1, also from this path.

However, my code depends on R6 >= V.2.2.2, which I have in .libPaths()[1].

It would be simple enough to have my SysAdmin update R6 in .libPaths()[2], but they cannot because other people's apps depend on the libraries on that path, and we don't want to break those.


I've tried:

  1. detaching R6 and loading it from .libPaths()[1]

    detach("package:R6", unload=TRUE, force = TRUE, character.only = TRUE)
    library(R6, lib.loc = "/zeolite/rpauloo/R/x86_64-pc-linux-gnu-library/3.4")  
    
  2. detaching shiny and loading it from .libPaths()[1]

    detach("package:shiny", unload=TRUE, force = TRUE, character.only = TRUE)
    library(shiny, lib.loc = "/zeolite/rpauloo/R/x86_64-pc-linux-gnu-library/3.4")  
    
  3. setting my .libPaths() from the start in the global.R file to only include the path I want.

    .libPaths(.libPaths()[1])
    
  4. adding an etc folder under "/zeolite/rpauloo/R" that contains the following Rprofile.site file (advice from here):

    .First <- function(){
      .libPaths("/zeolite/rpauloo/R/x86_64-pc-linux-gnu-library/3.4")
    }
    

None of these approaches work. Why?

  1. R6 is an attached package, so it can't be unloaded.
  2. not sure why unloading/reloading shiny doesn't work
  3. Shiny Server loads shiny from .libPaths()[2] to begin with, before the global.R file is sourced, so setting libPaths() doesn't help.
  4. the Rprofile.site file is probably in the wrong directory, but putting it in an admin directory will mess with other apps

Question

How can I configure my shiny app to load shiny from a specific .libPath on startup?

Or have I mis-conceptualized the problem? Is there another way to go about this?

Rich Pauloo
  • 7,734
  • 4
  • 37
  • 69
  • 1
    Is the shiny server running as its own user? I believe you can alter the `.libPaths()` in `global.R` probably - however this still seems a bit hacky. Refer to: https://stackoverflow.com/questions/15170399/change-r-default-library-path-using-libpaths-in-rprofile-site-fails-to-work Also maybe https://kb.iu.edu/d/avks? – zacdav Nov 14 '18 at 00:53
  • @zacdav, thanks for taking a look. I've updated my question to reflect this. The problem is that when I update my `.libPaths()` in `global.R` to only include the ones I want, Shiny Server has already loaded `shiny`, and attached the old version of `R6`. I'm not sure what you mean by "running as its own user". – Rich Pauloo Nov 14 '18 at 01:16
  • 1
    The shiny server will be running on a server as a specific user, I believe that this dictates permissions and where it looks for packages by default. So one solution would be to have shiny server running for each user and each user can then maintain the packages as they wish - bit of a nightmare for someone managing it though. Additionally, `Global.R` is run before the server has initialised (at least I thought it was), so if the first line was updating `.libPaths` i'm surprised it didn't work. – zacdav Nov 14 '18 at 02:20
  • @zacdav, yeah I also thought `.libPaths(.libPaths()[1])` at the start of the `global.R` file would also work, but the error I get still indicates that shiny is loaded from `.libPaths()[2]` (I can tell because the version number). Maybe some `.Rprofile` or `Rprofile.site` file is running first and kick-starting this chain? I've updated the list of things I've tried. – Rich Pauloo Nov 14 '18 at 17:30
  • Does the user that the shiny server is running as have read/write access to those paths? – zacdav Nov 14 '18 at 23:08
  • I have read/write access to all paths but the admin's, which is `.libPaths()[2]`. – Rich Pauloo Nov 15 '18 at 00:22
  • But what I'm saying is that the server doesn't run as if it was you, but as if it was another user. So if the user the shiny server is, is not you, it needs the correct permissions. – zacdav Nov 15 '18 at 01:10

0 Answers0