Trouble installing local R library on docker

Viewed 729

I am trying to deploy my Shiny app on docker (using the rocker/shiny-verse:3.6.3 base image) but I'm facing issues when I try installing local (non-CRAN) packages via docker. The installation works fine when done within RStudio.

  • Docker Engine v19.03.13

  • OS: Windows 10 Enterprise

Success - When I try installing the local package within RStudio:

> install.packages("<FULLPATH>/customLibrary.zip", repos = NULL, type = "win.binary")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/p/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
package ‘customLibrary’ successfully unpacked and MD5 sums checked

Dockerfile

FROM rocker/shiny-verse:3.6.3
RUN R -e "install.packages('<FULLPATH>/customLibrary.zip', repos = NULL, type = 'win.binary')"
RUN R -e "install.packages(c('gtable', 'data.table', 'shinydashboard', 'ggplot2'), repos='https://cran.rstudio.com', dependencies=FALSE)"
COPY . /srv/shiny-server
EXPOSE 3838

Failure - When I build my Docker image using aforementioned Dockerfile:

[+] Building 0.8s (6/8)
 => [internal] load build definition from Dockerfile                                                                                                    0.1s
 => => transferring dockerfile: 465B                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                       0.1s
 => => transferring context: 2B                                                                                                                         0.0s
 => [internal] load metadata for docker.io/rocker/shiny-verse:3.6.3                                                                                     0.0s
 => CACHED [1/4] FROM docker.io/rocker/shiny-verse:3.6.3                                                                                                0.0s
 => [internal] load build context                                                                                                                       0.0s
 => => transferring context: 517B                                                                                                                       0.0s
 => ERROR [2/4] RUN R -e "install.packages('<FULLPATH>/customRLibrary.zip', repos = NULL, type = 'win.bin  0.7s
------
 > [2/4] RUN R -e "install.packages('<FULLPATH>/customRLibrary.zip', repos = NULL, type = 'win.binary')":
#5 0.599
#5 0.599 R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
#5 0.599 Copyright (C) 2020 The R Foundation for Statistical Computing
#5 0.599 Platform: x86_64-pc-linux-gnu (64-bit)
#5 0.599
#5 0.599 R is free software and comes with ABSOLUTELY NO WARRANTY.
#5 0.599 You are welcome to redistribute it under certain conditions.
#5 0.599 Type 'license()' or 'licence()' for distribution details.
#5 0.599
#5 0.599 R is a collaborative project with many contributors.
#5 0.599 Type 'contributors()' for more information and
#5 0.599 'citation()' on how to cite R or R packages in publications.
#5 0.599
#5 0.599 Type 'demo()' for some demos, 'help()' for on-line help, or
#5 0.599 'help.start()' for an HTML browser interface to help.
#5 0.599 Type 'q()' to quit R.
#5 0.599
#5 0.723 > install.packages('<FULLPATH>/customRLibrary.zip', repos = NULL, type = 'win.binary')
#5 0.728 Installing package into ‘/usr/local/lib/R/site-library’
#5 0.728 (as ‘lib’ is unspecified)
#5 0.728 Error in install.packages("<FULLPATH>/customRLibrary.zip",  :
#5 0.728   cannot install Windows binary packages on this platform
#5 0.728 Execution halted
------
failed to solve with frontend dockerfile.v0: failed to build LLB: executor failed running [/bin/sh -c R -e "install.packages('<FULLPATH>/customRLibrary.zip', repos = NULL, type = 'win.binary')"]: runc did not terminate sucessfully

Could someone point out where I'm going wrong? TIA.

2 Answers

In RStudio, where you develop your package, install devtools and then run

devtools::build(binary = FALSE)

It will produce a tar.gz package that can be installed on any platform.

Here's the documentation: https://rdrr.io/cran/devtools/man/build.html

The rocker-org/shiny dockerfile is build upon Debian.

This is a Dockerfile for Shiny Server on Debian stable.

See on GitHub and on DockerHub - here is the dockerfile.

This means that the comments to your OP are correct. You are trying to install a windows binary on a linux, which does not work. Consequently, your problem is here.

install.packages("<FULLPATH>/customLibrary.zip", repos = NULL, type = "win.binary")

I guess that the solution is to compile your customLibrary for linux and simply do

install.packages("<FULLPATH>/customLibrary.zip", repos = NULL)
Related