5

It seems weird to me that my shiny app runs fine when I run from Rstudio but same project, when ran on shiny server (open source), does not use packrat private library. I used .libPaths() to check and the private library does not show. Do I need to do any configuration to make it work? Thanks.

paste0(.libPaths(),' shinyBS version:',as.character(packageVersion('shinyBS')))

On Rstudio

[1] "C:/R/ADAP/packrat/lib/i386-w64-mingw32/3.1.1 shinyBS version:0.25"
[2] "C:/R/ADAP/packrat/lib-ext shinyBS version:0.25"                   
[3] "C:/R/ADAP/packrat/lib-R shinyBS version:0.25"

On Shiny Server

shinyBS version:0.20 Lib:/usr/lib64/R/library shinyBS version:0.20 Lib:/usr/share/R/library
Florian
  • 24,425
  • 4
  • 49
  • 80
Xiushi Le
  • 245
  • 3
  • 16

2 Answers2

2

There is a config file .Renviron and in it contains an environment variable R_LIBS. This is where your R session (and .libPaths()) learns where to look for libraries. To change the default, do not edit the .Renviron file directly, but instead create a copy in the same directory and name it .Renviron.site. Edit the R_LIBS variable in this new file. This prevents your config changes from being overwritten by the installer on upgrades.

1

I am able to get packrat to work with shiny server open source.

Here is my directory structure in CentOS:

/srv/shiny-server/sample-apps/test1/
  .Rprofile
  packrat/
  server.R
  ui.R

In this example, I've copied the packrat produced .Rprofile file and the packrat/ directory (containing the compiled libs) along with the server.R and ui.R files to the test1 directory.

When the R process is created for the app, the packrat libs are loaded correctly.

For verification, I can then do:

cd /srv/shiny-server/sample-apps/
sudo cp -r test1 test2
cd test2
sudo rm .Rprofile
sudo rm -rf packrat/

Then, when I visit http://localhost:3838/sample-apps/test2/ the packrat libs are not loaded.

Note that the Shiny Server must be restarted for changes to take effect in certain cases (for example, if users are currently using the app, the R process for that app will not reload the new libs automatically). Restart with sudo systemctl restart shiny-server (on CentOS).

rmg
  • 1,009
  • 16
  • 31