Dockerizing a shiny app with an error in the building process

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

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如下:

  1. FROM rocker/shiny:latest
  2. RUN apt-get update -qq && apt-get -y --no-install-recommends install \
  3. libxml2-dev \
  4. libxml2 \
  5. libcairo2-dev \
  6. libsqlite3-dev \
  7. libmariadbd-dev \
  8. libpq-dev \
  9. libssh2-1-dev \
  10. unixodbc-dev \
  11. libcurl4-openssl-dev \
  12. libssl-dev
  13. ## update system libraries
  14. RUN apt-get update && \
  15. apt-get upgrade -y && \
  16. apt-get -y install r-cran-curl && \
  17. apt-get clean
  18. # copy necessary files
  19. ## renv.lock file
  20. COPY /app/renv.lock ./renv.lock
  21. ## app folder
  22. COPY /app ./app
  23. # install renv & restore packages
  24. RUN Rscript -e 'install.packages("renv")'
  25. RUN Rscript -e 'renv::restore()'
  26. # expose port
  27. EXPOSE 3838
  28. # run app on container start
  29. CMD ["R", "-e", "shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]

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

  1. FROM rocker/shiny:latest
  2. RUN apt-get update -qq && apt-get -y --no-install-recommends install \
  3. libxml2-dev \
  4. libxml2 \
  5. libcairo2-dev \
  6. libsqlite3-dev \
  7. libmariadbd-dev \
  8. libpq-dev \
  9. libssh2-1-dev \
  10. unixodbc-dev \
  11. libcurl4-openssl-dev \
  12. libssl-dev
  13. ## update system libraries
  14. RUN apt-get update && \
  15. apt-get upgrade -y && \
  16. apt-get -y install r-cran-curl && \
  17. apt-get clean
  18. # copy necessary files
  19. ## renv.lock file
  20. COPY /app/renv.lock ./renv.lock
  21. ## app folder
  22. COPY /app ./app
  23. # install renv & restore packages
  24. RUN Rscript -e 'install.packages("renv")'
  25. RUN Rscript -e 'renv::restore()'
  26. # expose port
  27. EXPOSE 3838
  28. # run app on container start
  29. 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:

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

  1. docker build -t actividades .
  2. 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:

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

  1. #0 2987.8 Using PKG_LIBS=-lfreetype -lharfbuzz -lfribidi -lpng
  2. #0 2987.8 --------------------------- [ANTICONF] --------------------------------
  3. #0 2987.8 Configuration failed to find the harfbuzz freetype2 fribidi library. Try installing:
  4. #0 2987.8 * deb: libharfbuzz-dev libfribidi-dev (Debian, Ubuntu, etc)
  5. #0 2987.8 * rpm: harfbuzz-devel fribidi-devel (Fedora, EPEL)
  6. #0 2987.8 * csw: libharfbuzz_dev libfribidi_dev (Solaris)
  7. #0 2987.8 * brew: harfbuzz fribidi (OSX)
  8. #0 2987.8 If harfbuzz freetype2 fribidi is already installed, check that 'pkg-config' is in your
  9. #0 2987.8 PATH and PKG_CONFIG_PATH contains a harfbuzz freetype2 fribidi.pc file. If pkg-config
  10. #0 2987.8 is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
  11. #0 2987.8 R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
  12. #0 2987.8 -------------------------- [ERROR MESSAGE] ---------------------------
  13. #0 2987.8 <stdin>:1:10: fatal error: hb-ft.h: No such file or directory
  14. #0 2987.8 compilation terminated.
  15. #0 2987.8 --------------------------------------------------------------------
  16. #0 2987.8 ERROR: configuration failed for package ‘textshaping’
  17. #0 2987.8 * removing ‘/usr/local/lib/R/site-library/.renv/1/textshaping’
  18. #0 2987.8 Error: install of package 'textshaping' failed [error code 1]
  19. #0 2987.9 Traceback (most recent calls last):
  20. #0 2987.9 12: renv::restore()
  21. #0 2987.9 11: renv_restore_run
  22. <details>
  23. <summary>英文:</summary>
  24. 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.
  25. One of the things I saw different is the structure of the app. Most of them, not all, have the simplest structure:
  26. -app &lt;br/&gt;
  27. |&lt;br/&gt;
  28. |-ui.R &lt;br/&gt;
  29. |-server.R &lt;br/&gt;
  30. dockerfile
  31. A folder called app with both files, ui and server and at the level of the folder the dockerfile.
  32. My structure is a little bit different.
  33. - app&lt;br/&gt;
  34. * renv &lt;br/&gt;
  35. * library
  36. * activate.R
  37. * settings.json
  38. * src&lt;br/&gt;
  39. * Carga_datos.R &lt;br/&gt;
  40. * packages.R &lt;br/&gt;
  41. * Descriptivo_aplicacion.R &lt;br/&gt;
  42. * www &lt;br/&gt;
  43. * image.png
  44. * server.R&lt;br/&gt;
  45. * ui.R &lt;br/&gt;
  46. * app.R &lt;br/&gt;
  47. - dockerfile
  48. 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)"]

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

docker build -t actividades .

  1. I cannot see the error, to be honest.
  2. 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.
  3. EDIT:
  4. 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

  1. EDIT 2:
  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/')"

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

docker run --rm -p 3838:3838 actividades

  1. 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?
  2. Thank you in advance because the problem is evolving :)
  3. [1]: https://stackoverflow.com/questions/44406631/deploy-shiny-app-in-rocker-shiny-docker
  4. </details>
  5. # 答案1
  6. **得分**: 1
  7. 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:
  8. RUN R -e "install.packages(c('shiny', 'rmarkdown'), repos='https://cloud.r-project.org/')"
  9. <details>
  10. <summary>英文:</summary>
  11. 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:
  12. RUN R -e &quot;install.packages(c(&#39;shiny&#39;, &#39;rmarkdown&#39;), repos=&#39;https://cloud.r-project.org/&#39;)&quot;
  13. </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:

确定