Dockerizing a shiny app with an error in the building process

huangapple go评论67阅读模式
英文:

Dockerizing a shiny app with an error in the building process

问题

I built a shiny app couple of months ago and i've been trying to deploy it into a docker for a while...with no success. I checked some other questions like [this one][1] and some other webs, youtube videos but I always get errors builing it.

一段时间前,我创建了一个Shiny应用程序,一直在尝试将其部署到Docker中...但一直没有成功。我查看了一些类似于[这个问题][1]以及其他一些网站和YouTube视频,但每次构建时都会出现错误。

One of the things I saw different is the structure of the app. Most of them, not all, have the simplest structure:

其中一个我发现不同的是应用程序的结构。大多数应用程序,而不是全部,都具有最简单的结构:

  • app
    |
    |-ui.R
    |-server.R
    dockerfile

一个名为app的文件夹,其中包含ui和server两个文件,以及与文件夹同级的dockerfile。

My structure is a little bit different.

我的结构略有不同。

  • app
    • renv
      • library
      • activate.R
      • settings.json
    • src
      • Carga_datos.R
      • packages.R
      • Descriptivo_aplicacion.R
    • www
      • image.png
    • server.R
    • ui.R
    • app.R
  • dockerfile

我的结构略有不同。

My last try with the dockerfile was:

我最后一次尝试使用Dockerfile如下:

FROM rocker/shiny:latest

RUN apt-get update -qq && apt-get -y --no-install-recommends install \
    libxml2-dev \
    libxml2 \
    libcairo2-dev \
    libsqlite3-dev \
    libmariadbd-dev \
    libpq-dev \
    libssh2-1-dev \
    unixodbc-dev \
    libcurl4-openssl-dev \
    libssl-dev

## update system libraries
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get -y install r-cran-curl && \
    apt-get clean

# copy necessary files
## renv.lock file
COPY /app/renv.lock ./renv.lock

## app folder
COPY /app ./app

# install renv & restore packages
RUN Rscript -e 'install.packages("renv")'
RUN Rscript -e 'renv::restore()'

# expose port
EXPOSE 3838

# run app on container start
CMD ["R", "-e", "shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]

我的最后一次尝试使用Dockerfile如下:

FROM rocker/shiny:latest

RUN apt-get update -qq && apt-get -y --no-install-recommends install \
    libxml2-dev \
    libxml2 \
    libcairo2-dev \
    libsqlite3-dev \
    libmariadbd-dev \
    libpq-dev \
    libssh2-1-dev \
    unixodbc-dev \
    libcurl4-openssl-dev \
    libssl-dev

## update system libraries
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get -y install r-cran-curl && \
    apt-get clean

# copy necessary files
## renv.lock file
COPY /app/renv.lock ./renv.lock

## app folder
COPY /app ./app

# install renv & restore packages
RUN Rscript -e 'install.packages("renv")'
RUN Rscript -e 'renv::restore()'

# expose port
EXPOSE 3838

# run app on container start
CMD ["R", "-e", "shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]

Errors had been changing, every time I try to create the container with the sentence:

错误一直在变化,每次我尝试使用以下命令创建容器时:

docker build -t actividades .

docker build -t actividades .

I cannot see the error, to be honest.

老实说,我看不到错误。

Thank in advanced and in case more information is needed...happy to share, even to create a repo in github and give access to the code, no problem at all.

提前感谢,如果需要更多信息...乐意分享,甚至创建一个GitHub仓库并提供代码访问权限,完全没问题。

EDIT:

编辑:

I am adding the last part of the message error:

我添加错误消息的最后部分:

#0 2987.8 Using PKG_LIBS=-lfreetype -lharfbuzz -lfribidi -lpng
#0 2987.8 --------------------------- [ANTICONF] --------------------------------
#0 2987.8 Configuration failed to find the harfbuzz freetype2 fribidi library. Try installing:
#0 2987.8  * deb: libharfbuzz-dev libfribidi-dev (Debian, Ubuntu, etc)
#0 2987.8  * rpm: harfbuzz-devel fribidi-devel (Fedora, EPEL)
#0 2987.8  * csw: libharfbuzz_dev libfribidi_dev (Solaris)
#0 2987.8  * brew: harfbuzz fribidi (OSX)
#0 2987.8 If harfbuzz freetype2 fribidi is already installed, check that 'pkg-config' is in your
#0 2987.8 PATH and PKG_CONFIG_PATH contains a harfbuzz freetype2 fribidi.pc file. If pkg-config
#0 2987.8 is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
#0 2987.8 R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
#0 2987.8 -------------------------- [ERROR MESSAGE] ---------------------------
#0 2987.8 <stdin>:1:10: fatal error: hb-ft.h: No such file or directory
#0 2987.8 compilation terminated.
#0 2987.8 --------------------------------------------------------------------
#0 2987.8 ERROR: configuration failed for package ‘textshaping’
#0 2987.8 * removing ‘/usr/local/lib/R/site-library/.renv/1/textshaping’
#0 2987.8 Error: install of package 'textshaping' failed [error code 1]
#0 2987.9 Traceback (most recent calls last):
#0 2987.9 12: renv::restore()
#0 2987.9 11: renv_restore_run

<details>
<summary>英文:</summary>

I built a shiny app couple of months ago and i&#39;ve been trying to deploy it into a docker for a while...with no success. I checked some other questions like [this one][1] and some other webs, youtube videos but I always get errors builing it.

One of the things I saw different is the structure of the app. Most of them, not all, have the simplest structure: 

-app &lt;br/&gt;
|&lt;br/&gt;
|-ui.R &lt;br/&gt;
|-server.R &lt;br/&gt;
dockerfile

A folder called app with both files, ui and server and at the level of the folder the dockerfile. 

My structure is a little bit different.

- app&lt;br/&gt;
    * renv &lt;br/&gt;
        * library
        * activate.R
        * settings.json
    * src&lt;br/&gt;
        * Carga_datos.R &lt;br/&gt;
        * packages.R &lt;br/&gt;
        * Descriptivo_aplicacion.R &lt;br/&gt;
    * www &lt;br/&gt;
        * image.png 
    * server.R&lt;br/&gt;
    * ui.R &lt;br/&gt;
    * app.R &lt;br/&gt;
- dockerfile

My last try with the dockerfile was:

FROM rocker/shiny:latest

RUN apt-get update -qq && apt-get -y --no-install-recommends install
libxml2-dev
libxml2
libcairo2-dev
libsqlite3-dev
libmariadbd-dev
libpq-dev
libssh2-1-dev
unixodbc-dev
libcurl4-openssl-dev
libssl-dev

update system libraries

RUN apt-get update &&
apt-get upgrade -y &&
apt-get -y install r-cran-curl &&
apt-get clean

copy necessary files

renv.lock file

COPY /app/renv.lock ./renv.lock

app folder

COPY /app ./app

install renv & restore packages

RUN Rscript -e 'install.packages("renv")'
RUN Rscript -e 'renv::restore()'

expose port

EXPOSE 3838

run app on container start

CMD ["R", "-e", "shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]

    Errors had been changing, every time I try to create the container with the sentence:

docker build -t actividades .


I cannot see the error, to be honest.

Thank in advanced and in case more information is needed...happy to share, even to create a repo in github and give access to the code, no problem at all.

EDIT: 

I am adding the last part of the message error:

#0 2987.8 Using PKG_LIBS=-lfreetype -lharfbuzz -lfribidi -lpng
#0 2987.8 --------------------------- [ANTICONF] --------------------------------
#0 2987.8 Configuration failed to find the harfbuzz freetype2 fribidi library. Try installing:
#0 2987.8 * deb: libharfbuzz-dev libfribidi-dev (Debian, Ubuntu, etc)
#0 2987.8 * rpm: harfbuzz-devel fribidi-devel (Fedora, EPEL)
#0 2987.8 * csw: libharfbuzz_dev libfribidi_dev (Solaris)
#0 2987.8 * brew: harfbuzz fribidi (OSX)
#0 2987.8 If harfbuzz freetype2 fribidi is already installed, check that 'pkg-config' is in your
#0 2987.8 PATH and PKG_CONFIG_PATH contains a harfbuzz freetype2 fribidi.pc file. If pkg-config
#0 2987.8 is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
#0 2987.8 R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
#0 2987.8 -------------------------- [ERROR MESSAGE] ---------------------------
#0 2987.8 <stdin>:1:10: fatal error: hb-ft.h: No such file or directory
#0 2987.8 compilation terminated.
#0 2987.8 --------------------------------------------------------------------
#0 2987.8 ERROR: configuration failed for package ‘textshaping’
#0 2987.8 * removing ‘/usr/local/lib/R/site-library/.renv/1/textshaping’
#0 2987.8 Error: install of package 'textshaping' failed [error code 1]
#0 2987.9 Traceback (most recent calls last):
#0 2987.9 12: renv::restore()
#0 2987.9 11: renv_restore_run_actions(project, diff, current, lockfile, rebuild)
#0 2987.9 10: renv_install_impl(records)
#0 2987.9 9: renv_install_staged(records)
#0 2987.9 8: renv_install_default(records)
#0 2987.9 7: handler(package, renv_install_package(record))
#0 2987.9 6: renv_install_package(record)
#0 2987.9 5: withCallingHandlers(renv_install_package_impl(record), error = function(e) {
#0 2987.9 vwritef("\tFAILED")
#0 2987.9 writef(e$output)
#0 2987.9 })
#0 2987.9 4: renv_install_package_impl(record)
#0 2987.9 3: r_cmd_install(package, path)
#0 2987.9 2: r_exec_error(package, output, "install", status)
#0 2987.9 1: stop(error)
#0 2989.1 Execution halted

Dockerfile:32

30 | # install renv & restore packages
31 | RUN Rscript -e 'install.packages("renv")'
32 | >>> RUN Rscript -e 'renv::restore()'
33 |
34 | # expose port

ERROR: failed to solve: process "/bin/sh -c Rscript -e 'renv::restore()'" did not complete successfully: exit code: 1


EDIT 2:

Now the dockerfile is compiled, I added:

install renv & restore packages

RUN R -e "install.packages(c('leaflet', 'dplyr', 'httr', 'jsonlite', 'shinyWidgets', 'shiny', 'stringr', 'tidyverse', 'htmltools', 'leaflet.extras', 'leaflet.extras2', 'raster', 'plotly', 'crosstalk', 'shinydashboard', 'later', 'htmlwidgets'), repos='https://cloud.r-project.org/')"

As suggested by Hailey but now when I try to execute the image:

docker run --rm -p 3838:3838 actividades


Everything looks fine but when I access to ```localhost:3838``` I got the error: ```object &#39;tidyverse&#39; not found``` which is included in the list of the packages to be installed. Any idea?

Thank you in advance because the problem is evolving :)

 

  [1]: https://stackoverflow.com/questions/44406631/deploy-shiny-app-in-rocker-shiny-docker

</details>


# 答案1
**得分**: 1

The docker image is not able to access your R environment to download packages. Instead of using `renv`, try to download each package in your Dockerfile. For example:

    RUN R -e "install.packages(c('shiny', 'rmarkdown'), repos='https://cloud.r-project.org/')"


<details>
<summary>英文:</summary>

The docker image is not able to access your R environment to download packages. Instead of using `renv`, try to download each package in your Dockerfile. For example:

    RUN R -e &quot;install.packages(c(&#39;shiny&#39;, &#39;rmarkdown&#39;), repos=&#39;https://cloud.r-project.org/&#39;)&quot;

</details>



huangapple
  • 本文由 发表于 2023年5月17日 17:03:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270326.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定