3

I'm relatively new to RShiny, Golem and Docker. However, I've built a little analytics dashboard with the Golem framework that I'd like to deploy locally using Docker.

I have been able to successfully build an image, but can't seem to get the container to run properly. When I do so, the container initialises and then halts with the following error:

> options('shiny.port'=80,shiny.host='0.0.0.0');ShinyPlatform::run_app()
Error in loadNamespace(x) : there is no package called ‘ShinyPlatform’
Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted

If it's any help, the command I'm using to run is the following:

docker run shinytest2

I'm also working within the project folder relative to the Rshiny app (don't know if that's any help).

Details are that it uses the renv and golem frameworks, and a mix of CRAN and local packages. Below is the dockerfile I'm using currently, most of it was automatically produced using golem::add_dockerfile(). The only lines that I've modified are the following :

RUN R -e 'install.packages("renv/local/LocalPackage1_0.1.0.tar.gz", repos= NULL, type = "source")'

RUN R -e 'install.packages("renv/local/ShinyPlatform_0.0.0.9000.tar.gz", repos = NULL, type = "source")'

The first above was to solve an error I was getting due to the LocalPackage1 not being found due to being housed in another folder. The second line was more of a trial I attempted, to see if I could do the same thing to solve the current error, no such luck so far, so I'm pretty sure it's wrong.

Here is the whole docker file:

FROM rocker/r-ver:4.1.1
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 && 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 R -e 'install.packages("remotes")'
RUN Rscript -e 'remotes::install_version("magrittr",upgrade="never", version = "2.0.1")'
RUN Rscript -e 'remotes::install_version("glue",upgrade="never", version = "1.4.2")'
RUN Rscript -e 'remotes::install_version("processx",upgrade="never", version = "3.5.2")'
RUN Rscript -e 'remotes::install_version("testthat",upgrade="never", version = "3.1.0")'
RUN Rscript -e 'remotes::install_version("htmltools",upgrade="never", version = "0.5.2")'
RUN Rscript -e 'remotes::install_version("attempt",upgrade="never", version = "0.3.1")'
RUN Rscript -e 'remotes::install_version("shiny",upgrade="never", version = "1.7.1")'
RUN Rscript -e 'remotes::install_version("config",upgrade="never", version = "0.3.1")'
RUN Rscript -e 'remotes::install_version("spelling",upgrade="never", version = "2.2")'
RUN Rscript -e 'remotes::install_version("thinkr",upgrade="never", version = "0.15")'
RUN Rscript -e 'remotes::install_version("shinyWidgets",upgrade="never", version = "0.6.2")'
RUN Rscript -e 'remotes::install_version("shinydashboard",upgrade="never", version = "0.7.2")'
RUN Rscript -e 'remotes::install_version("renv",upgrade="never", version = "0.14.0")'
RUN Rscript -e 'remotes::install_version("readxl",upgrade="never", version = "1.3.1")'
RUN Rscript -e 'remotes::install_version("gt",upgrade="never", version = "0.3.1")'
RUN Rscript -e 'remotes::install_version("golem",upgrade="never", version = "0.3.1")'
RUN R -e 'install.packages("renv/local/LocalPackage1_0.1.0.tar.gz", repos= NULL, type = "source")'
RUN R -e 'install.packages("renv/local/ShinyPlatform_0.0.0.9000.tar.gz", repos = NULL, type = "source")'
RUN Rscript -e 'remotes::install_version("DT",upgrade="never", version = "0.19")'
RUN Rscript -e 'remotes::install_version("DBI",upgrade="never", version = "1.1.1")'
RUN Rscript -e 'remotes::install_version("data.table",upgrade="never", version = "1.14.0")'
RUN echo "options(repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl', Ncpus = 4)" >> /usr/local/lib/R/etc/Rprofile.site
RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
RUN rm -rf /build_zone
EXPOSE 80
CMD R -e "options('shiny.port'=80,shiny.host='0.0.0.0');ShinyPlatform::run_app()"


Wondering if anyone might have any ideas as to why my container halts and can't seem to find the shiny app within it?

As mentioned, I'm quite new to both RShiny, Golem and Docker, so if I've left out any critical information, please let me know and I can update this post.

Jaimee-lee Lincoln
  • 365
  • 1
  • 3
  • 11

2 Answers2

0

Here's my guess as to what's going on:

  • R processes launched in your application's working directory will use the project-local library (as provisioned by renv);

  • R processes launched in other working directories will use the default user / site library (depending on how R has been configured)

In your Dockerfile, you're installing all of your packages first, before setting WORKDIR to your application's directory. This likely implies those packages are all being installed into the user / site libraries, which normally are not visible to renv projects.

In general, if you're using renv, it should suffice to have something like:

WORKDIR /path/to/project
RUN R -e 'renv::restore()'
RUN R -e <code>

where <code> is the R code required to run your application. (Include ADD and COPY statements in the Dockerfile as appropriate.)

The documentation at https://rstudio.github.io/renv/articles/docker.html may also be helpful.

Kevin Ushey
  • 20,530
  • 5
  • 56
  • 88
0

Is your package successfully installed inside your Docker image? What's the output in the logs of RUN R -e 'install.packages("renv/local/ShinyPlatform_0.0.0.9000.tar.gz", repos = NULL, type = "source")?

This error in your code usually means that the package containing the app isn't installed correctly — the issue is that install.packages doesn't throw a correct exit code when it fails, so the Docker image still compiles even if the packaged app fails to be installed.

Are

RUN R -e 'install.packages("renv/local/LocalPackage1_0.1.0.tar.gz", repos= NULL, type = "source")'
RUN R -e 'install.packages("renv/local/ShinyPlatform_0.0.0.9000.tar.gz", repos = NULL, type = "source")'

successful ?

Where are these files copied to the Docker build? You should have somewhere in your Dockerfile something that looks like

ADD renv ./renv

to have these tar.gz available to the build context.

Colin

Colin FAY
  • 4,849
  • 1
  • 12
  • 29