David
David

Reputation: 99

Cannot see the exposed Shiny app built with Docker and {golem}

I've been using the Golem framework for building R Shiny applications, which has been extremely helpful but I'm struggling with the docker file creation aspect of the framework.

Workflow:

In RStudio I create a new golem package, and insert a MIT license (without a license I receive a warning in devtools::check())

Run devtools::check() # Check passes no error no warnings

Run golem::add_dockerfile() # Which creates a Dockerfile in the project root

Close RStudio and open folder in VScode (docker build fails through RStudio)

docker build -t test .

docker run --rm -p 3838:3838 test

I now see the following console output

R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.    
You are welcome to redistribute it under certain conditions. 
Type 'license()' or 'licence()' for distribution details.    

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications. 

Type 'demo()' for some demos, 'help()' for on-line help, or  
'help.start()' for an HTML browser interface to help.        
Type 'q()' to quit R.

> options('shiny.port'=80,shiny.host='0.0.0.0');experimentdocker::run_app()
Loading required package: shiny

Listening on http://0.0.0.0:80

But when I navigate to http://0.0.0.0:80 I see "This page isn't working right now"

I'd really appreciate any support that can be offered.

I've included the standard golem dockerfile below.

FROM rocker/r-ver:4.1.0
RUN apt-get update && apt-get install -y  git-core libcurl4-openssl-dev libgit2-dev libicu-dev libssl-dev libxml2-dev make pandoc pandoc-citeproc && 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("shiny",upgrade="never", version = "1.6.0")'
RUN Rscript -e 'remotes::install_version("config",upgrade="never", version = "0.3.1")'
RUN Rscript -e 'remotes::install_version("golem",upgrade="never", version = "0.3.1")'
RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
RUN R -e 'remotes::install_local(upgrade="never")'
RUN rm -rf /build_zone
EXPOSE 80
CMD R -e "options('shiny.port'=80,shiny.host='0.0.0.0');experimentdocker::run_app()"

Upvotes: 2

Views: 702

Answers (1)

Sébastien Rochette
Sébastien Rochette

Reputation: 6671

I think a problem is that inside the Dockerfile, you EXPOSE port 80, but you export port 3838 outside your Docker container using docker run. You do not say where this port 80 is exposed on your localhost.
Instead, change port 80 to port 3838 inside the Dockerfile (in EXPOSE, and in shiny.port)

Dockerfile:

FROM rocker/r-ver:4.1.0
RUN apt-get update && apt-get install -y  git-core libcurl4-openssl-dev libgit2-dev libicu-dev libssl-dev libxml2-dev make pandoc pandoc-citeproc && 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("shiny",upgrade="never", version = "1.6.0")'
RUN Rscript -e 'remotes::install_version("config",upgrade="never", version = "0.3.1")'
RUN Rscript -e 'remotes::install_version("golem",upgrade="never", version = "0.3.1")'
RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
RUN R -e 'remotes::install_local(upgrade="never")'
RUN rm -rf /build_zone
EXPOSE 3838
CMD R -e "options('shiny.port'=3838,shiny.host='0.0.0.0');experimentdocker::run_app()"

Run. Note that these lines need to be run in a Terminal.

docker build -t test .
docker run --rm -p 3838:3838 test

And, then to navigate, you probably need http://localhost:3838

Upvotes: 3

Related Questions