Packages missing in shiny-server

后端 未结 6 2283
后悔当初
后悔当初 2020-12-18 11:48

I am trying to create a web application using shiny. It requires me to load a package I have installed on my computer. For example:

## Contents ui.R:
library         


        
相关标签:
6条回答
  • 2020-12-18 11:57

    Why do you need Plyr? nothing in your code is using it; but anyway, you can install packages on Linux R installation by running R , then, install.packages('plyr');

    0 讨论(0)
  • 2020-12-18 11:59

    I have upgraded from R 3.2 to 3.4 and faced the same issue, then i have created a folder named 3.4 in R/x86_64-pc-linux-gnu-library/ and copied everything from 3.2 folder (which is already there in the same location).

    0 讨论(0)
  • 2020-12-18 12:04

    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
    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("plyr")

    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.

    0 讨论(0)
  • 2020-12-18 12:13

    If the package is installed in your R library. The easiest way to make it run on shiny-server is to indicate to Shiny the library directory where the package is. Something like: library(plyr, lib.loc="/usr/local/lib/R/site-library") . If you have R-Studio installed, you can view the directory with .libPaths()

    0 讨论(0)
  • 2020-12-18 12:17

    Here might be a solution that doesn't mess up with the system library. Put the following code at the beginning of the server.R.

    user <- unname(Sys.info()["user"])
    if (user == "shiny") {
    
      # Set library locations
      .libPaths(c(
        "/path/to/your/own/library"
      )
      )
    
    }
    

    This lets Shiny look for packages installed in your own library preferentially and also keeps the packages you use to develop the app and the packages used when the app is deployed in sync.

    Note that you may need to tweak permissions of your library folder for the shiny user to see it properly. Otherwise it will fail to look into your specified location without any error message.

    0 讨论(0)
  • 2020-12-18 12:20

    Compare the output of .libPaths() in both cases and adjust accordingly in the server instance / your script.

    You may for example have the packages in "your" R package directory which the server cannot access. System-wide package installations are preferable in cases like this -- and are e.g. the default on Debian / Ubuntu.

    0 讨论(0)
提交回复
热议问题