如何确保在 Dockerfile 中本地安装我的 `{golem} `+ `{brochure}` Shiny App?

How do I ensure local installation of my `{golem} `+ `{brochure}` Shiny App in a Dockerfile?

问题:

  1. Where/How 我是否将使用 devtools::build() 构建的我自己的包下载到 Linux docker 文件系统中。

  2. tidyjson 安装失败,因为它需要 rlang 1.0.2 而我有 rlang 1.0.1 --> 由 golem::add_dockerfile()

背景:

我正在为我的 {golem} + {brochure} Shiny 应用编写一个 Dockerfile。我已经使用 golem::add_dockerfile 来启动构建的模板,并且只在其上添加。目前 .tar.gz 在我的项目根目录中。当我转到 运行 我的容器时遇到错误 --> Error in loadNamespace(x) : there is no package called ‘humblFinance’; Execution Halted,。这可能来自 CMD R -e "options(shiny.port = ${port}, shiny.host = '${host}') ; humblFinance::run_app().

Docker 文件


    FROM rocker/shiny-verse:4.1.3
    
    LABEL maintainer = "humblFinance <humblfinance@gmail.com>"
    
    RUN apt-get update && apt-get install -y \
    git-core \
    libcairo2-dev \
    libcurl4-openssl-dev \
    libgit2-dev libicu-dev \
    libssl-dev \
    libxml2-dev \
    make \
    pandoc \
    pandoc-citeproc \
    zlib1g-dev \
    libquantlib0-dev \
    && rm -rf /var/lib/apt/lists/*
    
    RUN echo "options(repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl', Ncpus = 4)"\
    >> /usr/local/lib/R/etc/Rprofile.site
    
    RUN install2.r --error --skipinstalled --deps TRUE \
        remotes
    
    RUN Rscript -e 'remotes::install_version("magrittr",upgrade="never", version = "2.0.2")'
    RUN Rscript -e 'remotes::install_version("rlang",upgrade="never", version = "1.0.1")'
    RUN Rscript -e 'remotes::install_version("glue",upgrade="never", version = "1.6.1")'
    RUN Rscript -e 'remotes::install_version("processx",upgrade="never", version = "3.5.2")'
    RUN Rscript -e 'remotes::install_version("stringr",upgrade="never", version = "1.4.0")'
    RUN Rscript -e 'remotes::install_version("lubridate",upgrade="never", version = "1.8.0")'
    RUN Rscript -e 'remotes::install_version("quantmod",upgrade="never", version = "0.4.18")'
    RUN Rscript -e 'remotes::install_version("htmltools",upgrade="never", version = "0.5.2")'
    RUN Rscript -e 'remotes::install_version("httr",upgrade="never", version = "1.4.2")'
    RUN Rscript -e 'remotes::install_version("zoo",upgrade="never", version = "1.8-9")'
    RUN Rscript -e 'remotes::install_version("xts",upgrade="never", version = "0.12.1")'
    RUN Rscript -e 'remotes::install_version("ggplot2",upgrade="never", version = "3.3.5")'
    RUN Rscript -e 'remotes::install_version("knitr",upgrade="never", version = "1.37")'
    RUN Rscript -e 'remotes::install_version("testthat",upgrade="never", version = "3.0.4")'
    RUN Rscript -e 'remotes::install_version("shiny",upgrade="never", version = "1.7.1")'
    RUN Rscript -e 'remotes::install_version("PerformanceAnalytics",upgrade="never", version = "2.0.4")'
    RUN Rscript -e 'remotes::install_version("shinyWidgets",upgrade="never", version = "0.6.4")'
    RUN Rscript -e 'remotes::install_version("rmarkdown",upgrade="never", version = "2.12")'
    RUN Rscript -e 'remotes::install_version("DT",upgrade="never", version = "0.21")'
    RUN Rscript -e 'remotes::install_version("here",upgrade="never", version = "1.0.1")'
    RUN Rscript -e 'remotes::install_version("config",upgrade="never", version = "0.3.1")'
    RUN Rscript -e 'remotes::install_version("attempt",upgrade="never", version = "0.3.1")'
    RUN Rscript -e 'remotes::install_version("covr",upgrade="never", version = "3.5.1")'
    RUN Rscript -e 'remotes::install_version("spelling",upgrade="never", version = "2.2")'
    RUN Rscript -e 'remotes::install_version("tidyquant",upgrade="never", version = "1.0.3")'
    RUN Rscript -e 'remotes::install_version("tidyjson",upgrade="never", version = "0.3.1")'
    RUN Rscript -e 'remotes::install_version("thinkr",upgrade="never", version = "0.15")'
    RUN Rscript -e 'remotes::install_version("thematic",upgrade="never", version = "0.1.2.1")'
    RUN Rscript -e 'remotes::install_version("runner",upgrade="never", version = "0.4.1")'
    RUN Rscript -e 'remotes::install_version("polished",upgrade="never", version = "0.6.1")'
    RUN Rscript -e 'remotes::install_version("golem",upgrade="never", version = "0.3.2")'
    RUN Rscript -e 'remotes::install_version("colourpicker",upgrade="never", version = "1.1.1")'
    RUN Rscript -e 'remotes::install_version("checkmate",upgrade="never", version = "2.0.0")'
    RUN Rscript -e 'remotes::install_version("bs4Dash",upgrade="never", version = "2.0.3")'
    RUN Rscript -e 'remotes::install_version("bizdays",upgrade="never", version = "1.0.9")'
    RUN Rscript -e 'remotes::install_version("assert",upgrade="never", version = "1.0.1")'
    RUN Rscript -e 'remotes::install_github("RinteRface/fullPage@4657d86a0cf43bb6b2451f5ee34b2410656bae0d")'
    RUN Rscript -e 'remotes::install_github("ColinFay/brochure@57d10e620b69256680a7244edf309e39243415af")'
    RUN Rscript -e 'remotes::install_version("RQuantLib",upgrade="never", version = "0.4.15")'
    
    #Adding RQuantLib
    
    RUN mkdir /build_zone
    ADD . /build_zone
    WORKDIR /build_zone
    RUN R -e 'remotes::install_local(upgrade="never")'
    RUN rm -rf /build_zone
    
    # add user group `app` and user `app`
    #RUN addgroup --system app \
     #   && adduser --system --ingroup app app
    
    # Copy Project files and edit app permisions
    # COPY . ./humblFinance
    # WORKDIR /humblFinance
    # RUN chown app:app -R ./humblFinance
    
    #USER app
    
    # Specify port
    ENV port 2811
    # Specify host
    ENV host 0.0.0.0
    
    # HARD CODED RN --> MAKE into ARG 
    EXPOSE 2811
    
    CMD R -e "options(shiny.port = ${port}, shiny.host = '${host}') ; humblFinance::run_app()"

描述

Package: humblFinance
Title: finance Shiny App
Version: 0.0.0.9000
Authors@R: person('humbl', 'Finance', email = 'humblfinance@gmail.com', role = c('cre', 'aut'))
Description: A visualization of financial data loaded and ready to be spelunked by the public.
License: GPL (>= 3)
Imports: 
    assert,
    attempt (>= 0.3.1),
    bizdays,
    brochure (>= 0.0.0.9022),
    bs4Dash,
    checkmate,
    colourpicker,
    config (>= 0.3.1),
    DT (>= 0.20),
    fullPage,
    ggplot2,
    glue (>= 1.6.1),
    golem (>= 0.3.1),
    here (>= 1.0.1),
    htmltools (>= 0.5.2),
    httr,
    lubridate,
    magrittr,
    PerformanceAnalytics,
    polished,
    processx (>= 3.5.2),
    quantmod,
    rlang,
    RQuantLib,
    runner,
    shiny (>= 1.6.0),
    shinyWidgets,
    stringr,
    thematic,
    thinkr (>= 0.15),
    tidyjson (>= 0.3.1),
    tidyquant,
    xts,
    zoo
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
Suggests: 
    rmarkdown (>= 2.8),
    knitr (>= 1.33),
    spelling (>= 2.2),
    testthat (>= 3.0.0),
    covr
Config/testthat/edition: 3
Language: en-US
VignetteBuilder: knitr
URL: https://github.com/jjfantini/humblFinance.git
BugReports: https://github.com/jjfantini/humblFinance.git/issues

命名空间

# Generated by roxygen2: do not edit by hand

export(rescaled_range)
export(run_app)
import(bizdays)
import(bs4Dash)
import(fullPage)
import(ggplot2)
import(httr)
import(lubridate)
import(polished)
import(shiny)
import(xts)
import(zoo)
importFrom(PerformanceAnalytics,Return.calculate)
importFrom(assert,assert)
importFrom(brochure,brochureApp)
importFrom(brochure,page)
importFrom(checkmate,assertString)
importFrom(checkmate,checkDate)
importFrom(glue,glue)
importFrom(golem,activate_js)
importFrom(golem,add_resource_path)
importFrom(golem,bundle_resources)
importFrom(golem,favicon)
importFrom(golem,with_golem_options)
importFrom(graphics,abline)
importFrom(graphics,plot)
importFrom(graphics,segments)
importFrom(magrittr,"%<>%")
importFrom(magrittr,"%>%")
importFrom(polished,secure_server)
importFrom(polished,secure_ui)
importFrom(polished,sign_in_ui_default)
importFrom(quantmod,periodReturn)
importFrom(rlang,is_null)
importFrom(runner,mean_run)
importFrom(shiny,HTML)
importFrom(shiny,NS)
importFrom(shiny,column)
importFrom(shiny,shinyApp)
importFrom(shiny,tagAppendAttributes)
importFrom(shiny,tagList)
importFrom(shiny,tags)
importFrom(shinyWidgets,airDatepickerInput)
importFrom(shinyWidgets,updateAirDateInput)
importFrom(stats,sd)
importFrom(stringr,str_extract)
importFrom(stringr,str_replace_all)
importFrom(thematic,thematic_shiny)
importFrom(tidyquant,tq_mutate)

我试过的


    RUN R -e 'remotes::install_local(upgrade="never")' 
    
    # Should my .tar.gz file show up as a package in this list?
    > remotes::install_local(upgrade="never")
    Installing 14 packages: hardhat, tsfeatures, forecast, slider, plotly,
    rsample, recipes, timetk, janitor, alphavantager, tidyquant, tidyjson, 
    thinkr, polished

解决方案:

  • 我手动更新了rlang --> 1.0.2

  • 我已将 libquantlib0-dev 安装到 Linux Docker 图像上,以便 RQuantLib 正确安装并具有正确的依赖关系

  • reactlog_enable()添加了一个if(),这样我在生产时不需要{reactLog},但不需要comment/uncomment