【问题标题】:How do I ensure local installation of my `{golem} `+ `{brochure}` Shiny App in a Dockerfile?如何确保在 Dockerfile 中本地安装我的 `{golem} `+ `{brochure}` Shiny App?
【发布时间】:2022-07-14 00:13:35
【问题描述】:

问题:

  1. 我在哪里/如何将我自己使用 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()

Dockerfile


    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 https://stackoverflow.com/questions/50178013/docker-expose-using-run-time-environment-variables
    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)

我的尝试

  • 运行remotes::install_local() 会重新下载使用remotes::install_version() 指定的包,但不是所有包,还有一些不在DESCRIPTION 文件或NAMESPACE 中的包。从文档中,install_local(upgrade = "never") will search the "."path and install the packages in that directory. I'm not exactly too sure where these are coming from, some packages likeplotly+forecastare not available insearch(), I'm guessing they are deps of other packages used internally? I may just point this function straight to .tar.gzof my local{golem}`包。

  • 我使用包在我的 Linux 映像上安装了QuantLib --> libquantlib0-dev \,这解决了我的包无法从RQuantLib 包安装失败构建的错误。


    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

【问题讨论】:

  • 你遇到了什么错误?
  • 对不起,忘记完成 Q 的一部分,错误现在在上面描述,我会在诊断时继续添加 - 看起来我需要在 Linux 映像中安装 QuantLib 包作为依赖? @flaxon

标签: r docker shiny golem


【解决方案1】:

解决方案:

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

  • 我已将 libquantlib0-dev 安装到 Linux Docker 映像上,以便使用正确的依赖项正确安装 RQuantLib

!!! - 描述包需要与已安装的 DOCKERFILE 包匹配,否则构建将失败并且您的本地包安装将被删除

【讨论】:

    猜你喜欢
    • 2016-07-21
    • 2023-02-07
    • 2020-11-01
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-27
    • 1970-01-01
    相关资源
    最近更新 更多