为闪亮的应用程序构建Docker映像时出现R包依赖关系问题 [英] R package dependency issue in building docker image for shiny app

查看:167
本文介绍了为闪亮的应用程序构建Docker映像时出现R包依赖关系问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为闪亮的应用构建docker映像。我的docker映像已成功构建,但无法在localhost上启动。在检查映像构建过程中的日志时,我看到如下错误消息:

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

似乎有一些程序包依赖性问题。似乎程序包 leafpop 依赖于 sf 。不确定软件包单位 ......

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

我的问题是:


  1. 如何修改Dockerfil e解决此依赖性问题?我想这也是一个普遍的问题。...

  2. 我等了很长时间才完成图像构建过程。我应该如何修改Dockerfile,以便在某些软件包安装失败时停止构建过程?只是为了节省时间。

我的Dockerfile如下:

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"]


推荐答案

错误日志通常会告诉您问题出在哪里。对于 units 包,未找到系统库,即 libudunits2.so 。错误消息甚至告诉您如何安装。

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.
--------------------------------------------------------------------------------

由于基本映像基于debian映像,因此请使用 apt 软件包,即 libudunits2-dev 。使用 apt-get 安装该软件包可修复此错误。

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.

sf相关的错误如下:

* 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’

主要错误是找不到 gdal-config 或无法执行。经过一番谷歌搜索后,我们发现 libgdal-dev 软件包提供了 gdal-config ,使用 apt-get

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.

将来,我建议通过尝试以交互方式构建容器来进行调试,然后在Dockerfile中编写正确的命令。比交互式进行调试要容易得多迭代修改Dockerfile。

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.

关于secon d问题, install.packages 接受 Ncpus 参数,该参数将并行编译软件包(如果软件包支持)。这样可以大大减少构建时间。

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

这篇关于为闪亮的应用程序构建Docker映像时出现R包依赖关系问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆