10

Possible overlap:
Packages missing in shiny-server
R shiny / shiny-server - issue with finding packages
R - How to set the path of install.packages() for shiny server ? - Ubuntu

I have tried and read all of the above but still cannot get my Shiny Server to work at all.

I followed the installation instructions on http://www.rstudio.com/shiny/server/install-opensource, including the system-wide install of the shiny package:

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

Shiny Server is installed properly and running,

~# sudo start shiny-server
start: Job is already running: shiny-server

but when I browse to domain:3838 I can see the welcome to shiny page, with error

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

Opening R, install.packages('shiny', repos='http://cran.rstudio.com/') , and then library(shiny) or any other package, tells me it cannot be found.

I am really quite stuck, not only can I not install/load any packages, I can't seem to find where they are going.

EDIT:

install.packages(c("geonames"))  
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
  
> library()  
Warning message:  
In library() :  
  libraries ‘/usr/local/lib/R/site-library’, ‘/usr/lib/R/site-library’ contain n                          o packages

AND

> installed.packages()[,1:2]
           Package      LibPath
base       "base"       "/usr/lib/R/library"
boot       "boot"       "/usr/lib/R/library"
class      "class"      "/usr/lib/R/library"
cluster    "cluster"    "/usr/lib/R/library"
codetools  "codetools"  "/usr/lib/R/library"
compiler   "compiler"   "/usr/lib/R/library"
datasets   "datasets"   "/usr/lib/R/library"
foreign    "foreign"    "/usr/lib/R/library"
graphics   "graphics"   "/usr/lib/R/library"
grDevices  "grDevices"  "/usr/lib/R/library"
grid       "grid"       "/usr/lib/R/library"
KernSmooth "KernSmooth" "/usr/lib/R/library"
lattice    "lattice"    "/usr/lib/R/library"
MASS       "MASS"       "/usr/lib/R/library"
Matrix     "Matrix"     "/usr/lib/R/library"
methods    "methods"    "/usr/lib/R/library"
mgcv       "mgcv"       "/usr/lib/R/library"
nlme       "nlme"       "/usr/lib/R/library"
nnet       "nnet"       "/usr/lib/R/library"
parallel   "parallel"   "/usr/lib/R/library"
rpart      "rpart"      "/usr/lib/R/library"
spatial    "spatial"    "/usr/lib/R/library"
splines    "splines"    "/usr/lib/R/library"
stats      "stats"      "/usr/lib/R/library"
stats4     "stats4"     "/usr/lib/R/library"
survival   "survival"   "/usr/lib/R/library"
tcltk      "tcltk"      "/usr/lib/R/library"
tools      "tools"      "/usr/lib/R/library"
utils      "utils"      "/usr/lib/R/library"

Any help is greatly appreciated


SessionInfo:

> .libPaths() [1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library" [3] "/usr/lib/R/library"

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

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

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


 
llrs
  • 3,308
  • 35
  • 68
Smackboyg
  • 131
  • 1
  • 2
  • 10
  • So your problem essentially boils down to not being able to install (or possibly load) the shiny package (or any packages)? – Roland May 22 '14 at 10:01
  • Yes, I'm afraid it has nothing to do with shiny server. I just cannot seem to install and load any package. `install.packages('shiny', repos='http://cran.rstudio.com/') Installing package into ‘/usr/local/lib/R/site-library’` but browsing to `/usr/local/lib/R/site-library` tells me its empty. /usr/local/lib/R/site-library is in the .libPaths()? – Smackboyg May 22 '14 at 10:09
  • Have you checked the permissions? – Roland May 22 '14 at 10:50
  • I am not sure, I have only been working with Linux based system for two days (trying to get this working!). I assume so? I log in as root and can run as sudo? Please see my edits? Any suggestions? – Smackboyg May 22 '14 at 11:11
  • What error does install.packages give you? Clearly it isn't succeeding...? – Joe Cheng May 23 '14 at 02:54
  • Perhaps this can help: http://stackoverflow.com/a/32996405/1328355 – Bastiaan Quast Oct 07 '15 at 15:41

4 Answers4

15

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

The easiest (and safest IMHO) way to solve this issue, is to install the required packages using this user account (shiny). This can be done using the following steps.

  1. Set a password for the shiny user account using sudo passwd shiny, now enter and confirm a password
  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("shiny")

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

Community
  • 1
  • 1
Bastiaan Quast
  • 2,802
  • 1
  • 24
  • 50
  • 1
    I had to perform an additional step to get this to work. Navigate to `/etc/rstudio/rserver.conf` and add the line `auth-minimum-user-id=100`. This the min user id defaults to 1000 and my `shiny` user was 996, which did not allow me to log in. – Mxblsdl Nov 14 '20 at 04:19
5

I had similar issue. After reading the admin guide, here might be a solution for you.

You are having this error because whoever accessing the app does not have the shiny package installed. If you do less /etc/shiny-server/shiny-server.conf and you might notice the following on the first two lines:

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

In order to fix the issue, you may do either of the following:

  • Switch to user shiny and install all packages there. e.g., su shiny. However, this is going to duplicate your installed libraries for all users.
  • A clean way is to always run shiny from another user with all the packages, by editing run_as in /etc/shiny-server/shiny-server.conf. In this case, you may change the second line to run_as your_username shiny;, so that it looks for your .libPaths() and then shiny's .libPaths(). You may also add multiple users here.
Boxuan
  • 4,937
  • 6
  • 37
  • 73
0

I had similar troubles. Worked after I did the following instead of the one line installation of the package:

sudo su
R

then in R do:

install.packages('shiny', repos='http://cran.rstudio.com/')
library(shiny)
Jan Stanstrup
  • 1,152
  • 11
  • 28
  • Thanks for your answer. Unfortunately, it didn't help. I cannot seem to install/load any package. `install.packages('shiny', repos='http://cran.rstudio.com/') Installing package into ‘/usr/local/lib/R/site-library’` but browsing to /usr/local/lib/R/site-library tells me its empty. /usr/local/lib/R/site-library is in the .libPaths() – Smackboyg May 22 '14 at 10:11
  • I cannot comment on the other "thread" so I put it here. To see permissions of the folders inside the "package folders" do: `ls -la "/usr/local/lib/R/site-library" "/usr/lib/R/site-library" "/usr/lib/R/library"` To see permissions for the folders themselves do `ls -la /usr/local/lib/R/" "/usr/lib/R/" "/usr/lib/R/"` – Jan Stanstrup May 22 '14 at 20:01
0

I am also a newbie to Ubuntu and had similar problems. In my case the problem was that R packages were installed in the folders belonging to user 'ubuntu'. However they have to be available to the root.

I changed user to 'root' with the appropriate command and then ran the install.packages function from R

sudo -i
R

Hope it will help you on your way. At least your problem is not unique. I found a lot of useful tips by just googling around a bit. E.g.:

http://freigeist.devmag.net/r/773-deploying-shiny-server-on-amazon-some-troubleshoots-and-solutions.html

user3819568
  • 170
  • 1
  • 8