【问题标题】:Deploy shinyapp in Docker Error in shinyAppDir(x)在 ShinyAppDir(x) 中的 Docker 中部署 shinyapp
【发布时间】:2021-04-25 01:11:09
【问题描述】:

我有以下停靠文件

# Base image https://hub.docker.com/u/rocker/
FROM rocker/shiny:latest

# system libraries of general use
## install debian packages
RUN apt-get update -qq && apt-get -y --no-install-recommends install \
    libxml2-dev \
    libcairo2-dev \
    libsqlite3-dev \
    libmariadbd-dev \
    libpq-dev \
    libssh2-1-dev \
    unixodbc-dev \
    libcurl4-openssl-dev \
    libssl-dev \
    coinor-libcbc-dev coinor-libclp-dev libglpk-dev


## update system libraries
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get clean

# copy necessary files
## app folder
COPY ./app ./app

# Docker inheritance
FROM bioconductor/bioconductor_docker:RELEASE_3_12

RUN apt-get update
    RUN R -e 'BiocManager::install(ask = F)' && R -e 'BiocManager::install(c("rtracklayer", \
    "GenomicAlignments", "Biostrings", "SummarizedExperiment", "Rsamtools", ask = F))'


# install renv & restore packages
RUN Rscript -e 'install.packages("renv")'
RUN Rscript -e 'install.packages("devtools")'
RUN Rscript -e 'install.packages("shiny")'
RUN Rscript -e 'install.packages("shinyBS")'
RUN Rscript -e 'install.packages("ggvis")'
RUN Rscript -e 'install.packages("shinydashboardPlus")'
RUN Rscript -e 'install.packages("shinycssloaders")'
RUN Rscript -e 'install.packages("shinyWidgets")'
RUN Rscript -e 'install.packages("plotly")'
RUN Rscript -e 'install.packages("RSQLite")'
RUN Rscript -e 'install.packages("forecast", dependencies = TRUE)'
RUN Rscript -e 'install.packages("tsutils")'
RUN Rscript -e 'install.packages("readxl")'
RUN Rscript -e 'install.packages("tidyverse")'
RUN Rscript -e 'install.packages("knitr")'
RUN Rscript -e 'install.packages("knitcitations")'
RUN Rscript -e 'install.packages("nycflights13")'
RUN Rscript -e 'install.packages("Matrix")'
RUN Rscript -e 'install.packages("plotly")'
RUN Rscript -e 'install.packages("igraph")'
RUN Rscript -e 'install.packages("ggthemes")'
RUN Rscript -e 'install.packages("evaluate")'
RUN Rscript -e 'install.packages("psych")'
RUN Rscript -e 'install.packages("kableExtra")'
RUN Rscript -e 'install.packages("ggjoy")'
RUN Rscript -e 'install.packages("gtools")'
RUN Rscript -e 'install.packages("gridExtra")'
RUN Rscript -e 'install.packages("cowplot")'
RUN Rscript -e 'install.packages("ggrepel")'
RUN Rscript -e 'install.packages("data.table")'
RUN Rscript -e 'install.packages("stringr")'
RUN Rscript -e 'install.packages("rmarkdown")'

RUN Rscript -e 'install.packages("shinyjqui")'
#RUN Rscript -e 'install.packages("BiocManager")'
#RUN R -e 'BiocManager::install("rtracklayer")'
#RUN R -e 'BiocManager::install("GenomicAlignments")'
#RUN R -e 'BiocManager::install("Biostrings")'
#RUN R -e 'BiocManager::install("SummarizedExperiment")'
#RUN R -e 'BiocManager::install("Rsamtools")'
RUN Rscript -e 'install.packages("V8")'
RUN Rscript -e 'devtools::install_github("ThomasSiegmund/D3TableFilter")'
RUN Rscript -e 'devtools::install_github("leonawicz/apputils")'
RUN Rscript -e 'devtools::install_github("Marlin-Na/trewjb")'

RUN Rscript -e 'devtools::install_github("dirkschumacher/ompr")'
RUN Rscript -e 'devtools::install_github("dirkschumacher/ompr.roi")'

RUN Rscript -e 'install.packages("ROI.plugin.glpk")'

RUN Rscript -e 'install.packages("shinydashboard")'
RUN Rscript -e 'install.packages("dplyr")'
RUN Rscript -e 'install.packages("dashboardthemes")'
RUN Rscript -e 'install.packages("shinyjs")'
RUN Rscript -e 'install.packages("magrittr")'
RUN Rscript -e 'install.packages("DT")'
RUN Rscript -e 'install.packages("rhandsontable")'
RUN Rscript -e 'renv::consent(provided = TRUE)'
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)"]

当我尝试在没有 Bioconductor 包的情况下上传时,应用正在运行 但是,当我尝试作为 dockfile 上传时,我收到以下错误。

Bioconductor 版本 3.12 (BiocManager 1.30.10), ?BiocManager::install 寻求帮助 闪亮::runApp('/app', 主机 = '0.0.0.0', 端口 = 3838) shinyAppDir(x) 中的错误:路径“/app”中不存在 Shiny 应用程序 调用: ... as.shiny.appobj -> as.shiny.appobj.character -> shinyAppDir 执行停止

我访问了一些解决方案,但我不明白它们......请我需要你的帮助

【问题讨论】:

    标签: r docker shinyapps bioconductor


    【解决方案1】:

    查看multistage builds 上的文档 你有一个 COPY 语句,然后是一个 FROM 语句。在最后一条语句之后,您将无法再访问上一阶段中的任何内容。如果需要,您可以使用--from=stagename 将文件从一个阶段复制到下一个阶段,其中您使用 FROM somerepo/someimage as stagename 命名该阶段。 在这种情况下,这意味着您在第一阶段所做的一切都不再使用或可用。 通常这是使用类似的东西

    FROM baseimage as build
    RUN install some dependencies
    COPY some sourcefiles
    RUN install stuff eg mvn install
    
    FROM runImage as run
    COPY --from=build somepath/executable
    CMD ["do", "something"]
    

    通过这种方式,您可以保持最终图像较小,在构建时删除您需要的所有内容,而不是在运行时删除。 在你的情况下,你必须重新考虑一下,看看你在哪个阶段需要什么。

    我不知道你的应用程序的细节,但你现在设置它的方式是你从一个基础镜像开始,然后安装 debian suff,然后是系统的东西,然后从一个“空”的新基础镜像开始.您可能只想使用一张图像并从那里开始,只需一条FROM 指令。然后,如果您想针对生产对其进行优化,您可以随时考虑多阶段构建,如果这对您来说是值得的。

    【讨论】:

    • 非常感谢您的回答。但是是一个很难的概念。所以我需要 2 个 dockerfile(如建议的文章所述)一个将深入应用程序,另一个将部署 bioconductor 包?
    • 根据您的回答,我尝试在部署应用程序之前移动并发布 Bioconductor 块。该应用程序需要来自 Bioconductor 的库。一切似乎都在运行......也许是解决方案?更改 dockerfile 中的块?
    • 是的,正如我建议的那样,将所有内容都放在一个阶段,如果以后需要,您可以优化以获得更小的最终图像。
    猜你喜欢
    • 2015-06-29
    • 2015-10-11
    • 1970-01-01
    • 1970-01-01
    • 2022-10-16
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多