rdockershinygolem

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


Question:

  1. Where/How do I download my own package that is built with devtools::build() into the Linux docker filesystem.

  2. tidyjson is failing to install because it needs rlang 1.0.2 and I have rlang 1.0.1 --> which was determined from golem::add_dockerfile()

Background:

I am writing a Dockerfile for my {golem} + {brochure} Shiny app. I have used golem::add_dockerfile to start the template of the build and have only added on top of that. Currently the .tar.gz is in my project root dir. When I go to run my container I am met with an error --> Error in loadNamespace(x) : there is no package called ‘humblFinance’; Execution Halted,. This is likely coming from 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()"

DESCRIPTION

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

NAMESPACE

# 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)

What I've tried


    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


Solution

  • Solution:

    !!! - DESCRIPTION packages NEED to match the DOCKERFILE packages that are installed, otherwise the build will fail and your local package installation will be removed