首页 > 解决方案 > 使用 Docker 部署 R 闪亮的应用程序

问题描述

我正在尝试使用 Docker 部署 R 闪亮的应用程序。但是我不断收到以下错误,即应用程序所需的软件包未安装在 docker 上,即使我使用 Dockerfile 脚本安装了它们

'/var/log/shiny-server//shiny-server-shiny-20210531-160002-46437.log' has been created

***/var/log/shiny-server//shiny-server-shiny-20210531-160002-46437.log ***
su: ignoring --preserve-environment, its mutually exclusive with --login
Error in library(shinydashboard) : 
  there is no package called ‘shinydashboard’
Calls: runApp ... sourceUTF8 -> eval -> eval -> ..stacktraceon.. -> library
Execution halted  

我的 Dockerfile 看起来像这样


      FROM rocker/r-ver:3.6.3

      RUN apt-get update && apt-get install -y \
          sudo \
          gdebi-core \
          pandoc \
          pandoc-citeproc \
          libcurl4-gnutls-dev \
          libcairo2-dev \
          libxt-dev \
          xtail \
          wget

      #RUN sudo su - -c "R -e \"install.packages(c('plyr'), repos='http://cran.rstudio.com/')\""

      # Download and install shiny server
      RUN wget --no-verbose https://download3.rstudio.org/ubuntu-14.04/x86_64/VERSION -O 
            "version.txt" && \
                VERSION=$(cat version.txt)  && \
                wget --no-verbose "https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny- 
         server-$VERSION-amd64.deb" -O ss-latest.deb && \
          gdebi -n ss-latest.deb && \
          rm -f version.txt ss-latest.deb && \
          . /etc/environment && \
          R -e "install.packages(c('shiny', 
'plotly','shinydashboard','dplyr','ggplot2','DT','shinyjs','sodium','shinyWidgets','magrittr','tidyr','shinythemes'), repos='$MRAN')" && \
          cp -R /usr/local/lib/R/site-library/shiny/examples/* /srv/shiny-server/ && \
          chown shiny:shiny /var/lib/shiny-server

      EXPOSE 3838

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

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

我的 shiny-server.sh 文件如下所示:


      #!/bin/sh

      # Make sure the directory for individual app logs exists
      mkdir -p /var/log/shiny-server
      chown shiny.shiny /var/log/shiny-server

      if [ "$APPLICATION_LOGS_TO_STDOUT" != "false" ];
      then
          # push the "real" application logs to stdout with xtail in detached mode
          exec xtail /var/log/shiny-server/ &
      fi

      # start shiny server
      exec shiny-server 2>&1

标签: rdockershiny

解决方案


推荐阅读