R package dependency issue in building docker image for shiny app

大兔子大兔子 提交于 2020-06-01 05:13:26

问题


I'm trying to build a docker image for my shiny app. My docker image is 'successfully' built, but cannot be started on localhost. Checking the logs in image building process, I saw error messages like below:

ERROR: dependency ‘sf’ is not available for package ‘leafpop’
* removing ‘/usr/local/lib/R/site-library/leafpop’
..........

1: In install.packages(c("remotes", "shiny", "shinythemes", "shinydashboard",  :>
  installation of package ‘units’ had non-zero exit status
2: In install.packages(c("remotes", "shiny", "shinythemes", "shinydashboard",  :
  installation of package ‘sf’ had non-zero exit status
3: In install.packages(c("remotes", "shiny", "shinythemes", "shinydashboard",  :
  installation of package ‘leafpop’ had non-zero exit status

It looks like it has some package dependency issue. seems like package leafpop is dependent on sf. Not sure about package units......

My question is:

  1. How I should modify my Dockerfile to solve this dependency issues? I guess this is also a general question....
  2. I waited quite a while for the image building process to complete. How should I modify my Dockerfile, so that when some package installation failed, it stops the building process? just to save my time.

my Dockerfile is below:

FROM rocker/shiny-verse

RUN apt-get update && apt-get install -y \
    sudo \
    gdebi-core \
    pandoc \
    pandoc-citeproc \
    libcurl4-gnutls-dev \
    libcairo2-dev \
    libxt-dev \
    libssl-dev \
    libssh2-1-dev

RUN wget --no-verbose https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
    VERSION=$(cat version.txt)  && \
    wget --no-verbose "https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
    gdebi -n ss-latest.deb && \
    rm -f version.txt ss-latest.deb

RUN R -e "install.packages(c('remotes', 'shinythemes','shinydashboard','shinyWidgets','shinyjs', 'rlang','scales','DT','lubridate', 'plotly',  'leaflet', 'leafpop', 'visNetwork', 'wordcloud2', 'arules'), repos='http://cran.rstudio.com/')"
RUN R -e "remotes::install_github('nik01010/dashboardthemes')"


COPY shiny-server.conf  /etc/shiny-server/shiny-server.conf
COPY /app /srv/shiny-server/

EXPOSE 80

COPY shiny-server.sh /usr/bin/shiny-server.sh

CMD ["/usr/bin/shiny-server.sh"]

回答1:


The error logs will usually tell you what the problem was. In the case of the units package, a system library was not found, namely libudunits2.so. The error message even tells you how to install it.

--------------------------------------------------------------------------------
  Configuration failed because libudunits2.so was not found. Try installing:
    * deb: libudunits2-dev (Debian, Ubuntu, ...)
    * rpm: udunits2-devel (Fedora, EPEL, ...)
    * brew: udunits (OSX)
  If udunits2 is already installed in a non-standard location, use:
    --configure-args='--with-udunits2-lib=/usr/local/lib'
  if the library was not found, and/or:
    --configure-args='--with-udunits2-include=/usr/include/udunits2'
  if the header was not found, replacing paths with appropriate values.
  You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually.
--------------------------------------------------------------------------------

Because the base image is based on a debian image, use the apt package, which is libudunits2-dev. Installing that package with apt-get fixes this error.

The error relating to sf is as follows:

* installing *source* package ‘sf’ ...
** package ‘sf’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: gcc
configure: CXX: g++ -std=gnu++11
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘sf’
* removing ‘/usr/local/lib/R/site-library/sf’
cat: leafpop.out: No such file or directory

The downloaded source packages are in
    ‘/tmp/RtmpmvJxnC/downloaded_packages’
Warning message:
In install.packages(c("remotes", "shinythemes", "shinydashboard",  :
  installation of one or more packages failed,
  probably ‘sf’, ‘leafpop’

The main error there is that gdal-config is not found or not executable. After some googling, we find that the libgdal-dev package provides gdal-config. Installing that with apt-get solves that problem.

In the future, I recommend debugging by trying to build the container interactively. Then write the correct commands in a Dockerfile. It's easier to debug interactively than to iteratively modify your Dockerfile.


Regarding your second question, install.packages accepts an Ncpus argument, which will compile the packages in parallel (if the packages support that). This can significantly decrease your build times.

install.packages(... Ncpus=6)  # for example


来源:https://stackoverflow.com/questions/61853440/r-package-dependency-issue-in-building-docker-image-for-shiny-app

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