R shiny / shiny-server - issue with finding packages

天大地大妈咪最大 提交于 2019-12-20 11:08:46

问题


I have installed shiny and shiny-server on an ubuntu server. I did a similar install on a dev server which is working. R sessions when they open up load some packages. The app runs fine locally but I'm getting messages that it can't find the packages when running on shiny-server.

The error on the app

During startup - Warning messages:

1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘shiny’
2: package ‘shiny’ in options("defaultPackages") was not found 
3: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘data.table’
4: package ‘data.table’ in options("defaultPackages") was not found 
5: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘optiRum’
6: package ‘optiRum’ in options("defaultPackages") was not found 
Error in eval(expr, envir, enclos) : 
  The Shiny package was not found in the library. Ensure that 
Shiny is installed and is available in the Library of the 
user you're running this application as.
Calls: local -> eval.parent -> eval -> eval -> eval -> eval
Execution halted

In Rprofile.site I have

# ## Example of Rprofile.site
 local({
#  # add MASS to the default packages, set a CRAN mirror
  old <- getOption("defaultPackages"); r <- getOption("repos")
#  r["CRAN"] <- "http://my.local.cran"
  options(defaultPackages = c(old, "shiny","data.table","optiRum"), repos = r)
})

.First <- function() {
   cat("\n   Welcome to R!\n\n")
#    setwd("/home/OPTIMUMCREDIT/R/Projects")
    Sys.umask(mode="0002")
}
.libPaths(c("/home/R/WorkingPackages","/home/R/ApprovedPackages"))

In shiny-server config I have just the default config (so run as shiny and default port).

My sessionInfo()

> sessionInfo()
R version 3.0.3 (2014-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C            LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C        LC_PAPER=C          
 [8] LC_NAME=C            LC_ADDRESS=C         LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_0.9.3.1  scales_0.2.3     RCurl_1.95-4.1   bitops_1.0-6     rstudio_0.98.501 optiRum_0.30     data.table_1.9.2 shiny_0.8.0     

loaded via a namespace (and not attached):
 [1] MASS_7.3-29        RColorBrewer_1.0-5 RJSONIO_1.0-3      Rcpp_0.11.0        caTools_1.16       colorspace_1.2-4   dichromat_2.0-0   
 [8] digest_0.6.4       grid_3.0.3         gtable_0.1.2       httpuv_1.2.3       labeling_0.2       munsell_0.4.2      plyr_1.8.1        
[15] proto_0.3-10       reshape2_1.2.2     stringr_0.6.2      tools_3.0.3        xtable_1.7-3

I tried adding a message to output the libPaths above library(shiny) in my code but unfortunately the same error message happens. I did some uninstalling and reinstalling as I'd a bit unusually installed shiny-server first then remembered I needed shiny but no joy. I've confirmed that shiny is installed in ApprovedPackages. The packages at load up, I added in the hopes of circumventing the problem or finding out more information.

UPDATE - running as shiny Ah - the plot thickens... logging in with the user shiny on console caused the same warnings the app was getting, and .libPaths() is not like everyone else's:

> sessionInfo()
R version 3.0.3 (2014-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
[3] "/usr/lib/R/library"

I'm a bit stumped and was hoping someone could point me in the right direction to solve the problem.


回答1:


Sorry for the troubles. Can you try running the following command to install Shiny system-wide?

sudo su - \
  -c "R -e \"install.packages('shiny', repos='http://cran.rstudio.com/')\""

This comes from the Admin Guide which (hopefully) will serve as a useful resource on these kinds of issues.

I suspect that the problem is that Shiny is indeed properly installed in your user account, but because it wasn't installed as sudo, it's not available to the shiny user.

Edits:

You'll also need to make sure that Rprofile.site is being applied when the shiny user starts an R process. You can do this by logging in as shiny:

sudo su shiny

Then opening R and checking the .libPaths() or seeing if you can successfully run library(shiny) there. If you're not able to, there's probably an issue with letting the shiny user get into your shared packages directory or your Rprofile.site file (or its parent directory). Ensure that the shiny user is added to the necessary groups or that these files and all of their parent directories grant the appropriate permissions to the shiny user.



来源:https://stackoverflow.com/questions/22298187/r-shiny-shiny-server-issue-with-finding-packages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!