首页 > 解决方案 > 使用 Dockerfile 的 R 并行计算和 Shiny Server

问题描述

我需要一些帮助来使用并行计算和futureDocker 容器内的闪亮包。当我在 shinyapps.io 中插入我的应用程序时,它可以正常工作,但是如果我使用 Docker,它会给我以下日志错误。

[2019-04-22T19:49:24.320] [INFO] shiny-server - Shiny Server v1.5.7.890 (Node.js v8.10.0) [2019-04-22T19:49:24.325] [INFO] shiny-server - Using config file "/etc/shiny-server/shiny-server.conf" 
[2019-04-22T19:49:24.440] [INFO] shiny-server - Starting listener on 0.0.0.0:80
[2019-04-22T19:49:29.399] [INFO] shiny-server - Created bookmark state directory: /var/lib/shiny-server/bookmarks
[2019-04-22T19:49:29.401] [INFO] shiny-server - Created user bookmark state directory: /var/lib/shiny-server/bookmarks/shiny
[2019-04-22T19:50:30.486] [INFO] shiny-server - Error getting worker: Error: The application took too long to respond.
[2019-04-22T19:50:30.488] [INFO] shiny-server - Error getting worker: Error: The application took too long to respond.
[2019-04-22T19:50:30.489] [INFO] shiny-server - Error getting worker: Error: The application took too long to respond.

我的 Dockerfile 使用 R、闪亮服务器、与 Postgres 和 sqlite 的连接。如果我不使用future它,它可以正常工作。

# Install R version 3.5
FROM r-base:3.5.1

# Install Ubuntu packages
RUN apt-get update && apt-get install -y \
    sudo \
    gdebi-core \
    pandoc \
    pandoc-citeproc \
    libcurl4-gnutls-dev \
    libcairo2-dev/unstable \
    libxt-dev \
    libssl-dev \
    libpq-dev


# Download and install ShinyServer (latest version)
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


# Install SQLite
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get -yq install sqlite3 && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*


# Install R packages that are required
# TODO: add further package if you need!
RUN R -e "install.packages(c('RSQLite', 'RPostgres', 'readxl', 'dplyr', 'lubridate', 'DT', 'billboarder', 'shiny', 'future'), repos='http://cran.rstudio.com/')"


# Copy configuration files into the Docker image
COPY shiny-server.conf  /etc/shiny-server/shiny-server.conf
COPY /app /srv/shiny-server/


# Give permission of READWRITE for the SQLite database
RUN chmod a+rw /srv/shiny-server/db/ /srv/shiny-server/db/*


# Make the ShinyApp available at port 80
EXPOSE 80


# Copy further configuration files into the Docker image
COPY shiny-server.sh /usr/bin/shiny-server.sh


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

对于一个示例应用程序,我尝试了一个 global.R 文件加载shinyfuture执行类似的东西

library(shiny)
library(future)

plan(multiprocess) 
future({print(1)})

使用最少的 ui.R (like FluidPage()) 和 server.R (like server <- function(input, output) {})。我敢打赌,我使用的是 Windows 7 环境,这会导致multiprocess.像这样,我还没有找到。先感谢您。

标签: rdockershinyshiny-server

解决方案


推荐阅读