I want to develop a Shiny App in docker container, and run this app under a subfolder. Till now I just made it run and opened it through localhost:3838, how can I open it through localhost:3838/myapp?
My dockerfile is as follows:
FROM rocker/shiny
# Install system requirements for index.R as needed
RUN apt-get update && apt-get install -y \
--no-install-recommends \
git-core \
libssl-dev \
libcurl4-gnutls-dev \
curl \
libsodium-dev \
libxml2-dev \
libicu-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV _R_SHLIB_STRIP_=true
COPY Rprofile.site /etc/R
RUN R -e "install.packages('shiny', repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('remotes', repos='http://cran.rstudio.com/')"
COPY . /srv/shiny-server/
USER shiny
EXPOSE 3838
CMD ["/usr/bin/shiny-server"]
add I built and ran the container by the command:
docker build -t myapp .
docker run --rm -p 3838:3838 myapp
Related
My Dockerfile contains the exact code as shown in the statworx website to build an image for a Shiny app. Whenever I run the following code however:
# Base image https://hub.docker.com/u/rocker/
FROM rocker/shiny:latest
# system libraries of general use
## install debian packages
RUN apt-get update -qq && apt-get -y --no-install-recommends install
libxml2-dev
libcairo2-dev
libsqlite3-dev
libmariadbd-dev
libpq-dev
libssh2-1-dev
unixodbc-dev
libcurl4-openssl-dev
libssl-dev
## update system libraries
RUN apt-get update &&
apt-get upgrade -y &&
apt-get clean
# copy necessary files
## app folder
COPY /example-app ./app
## renv.lock file
COPY /example-app/renv.lock ./renv.lock
# install renv & restore packages
RUN Rscript -e 'install.packages("renv")'
RUN Rscript -e 'renv::consent(provided = TRUE)'
RUN Rscript -e 'renv::restore()'
# expose port
EXPOSE 3838
# run app on container start
CMD ["R", "-e", "shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]
docker build -t my-shinyapp-image .
I get the following error: failed to solve with frontend dockerfile.v0: failed to create LLB definition: dockerfile parse error line 7: unknown instruction: LIBXML2-DEV
If I remove the LIBXML2-DEV package it gives an error on the next one. Has anyone encountered this problem before?
Following the suggestion of #HubertL, here is the Dockerfile that will work:
# Base image https://hub.docker.com/u/rocker/
FROM rocker/shiny:latest
# system libraries of general use
## install Debian/Ubuntu packages
RUN apt-get update -qq && \
apt-get upgrade -y && \
apt-get -y --no-install-recommends install \
libxml2-dev \
libcairo2-dev \
libsqlite3-dev \
libmariadbd-dev \
libpq-dev \
libssh2-1-dev \
unixodbc-dev \
libcurl4-openssl-dev \
libssl-dev
## update system libraries
RUN apt-get update && \
apt-get upgrade -y && \
apt-get clean
# copy necessary files
## app folder
COPY /example-app ./app
## renv.lock file
COPY /example-app/renv.lock ./renv.lock
# install renv & restore packages
RUN Rscript -e 'install.packages("renv")'
RUN Rscript -e 'renv::consent(provided = TRUE)'
RUN Rscript -e 'renv::restore()'
# expose port
EXPOSE 3838
# run app on container start
CMD ["R", "-e", "shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]
I wrote the docker file like this to deploy the shiny r application
FROM rocker/r-base:latest\
RUN apt-get update && apt-get install -y --no-install-recommends \
sudo \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libssh2-1-dev \
&& rm -rf /var/lib/apt/lists/*
RUN install.r shiny
RUN install.r shinydashboard
RUN R -e "install.packages(c('ggmap','ggplot2','leaflet'),dependencies = TRUE, repos='http://cran.rstudio.com/')"
RUN echo "local(options(shiny.port = 3838, shiny.host = '0.0.0.0'))" > /usr/lib/R/etc/Rprofile.site
RUN addgroup --system app \
&& adduser --system --ingroup app app
WORKDIR /home/app
COPY app .
RUN chown app:app -R /home/app
USER app
EXPOSE 3838
CMD ["R", "-e", "shiny::runApp('/home/app')"]
next, I build a docker file
docker build -t test-shiny .
after run the build docker image
docker run -p 3838:3838 test-shiny
this time I got an error like this
my app Global.R file like this
library(shiny)
library(shinydashboard)
library(shinyMobile)
library(ggmap)
library(ggplot2)
library(leaflet)
what I can do fix leaflet package issue,
someone can help me!
I got a solution for that
RUN
sudo \
libgdal-dev \
libproj-dev \
libgeos-dev \
libudunits2-dev \
netcdf-bin \
Install these dependencies
I am a beginner in docker, my question can be considered somewhat obvious but where do I save and write the dockerfile?
example:
FROM openanalytics/r-base
LABEL maintainer "Tobias Verbeke <tobias.verbeke#openanalytics.eu>"
# system libraries of general use
RUN apt-get update && apt-get install -y \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libssh2-1-dev \
libssl1.0.0
# system library dependency for the euler app
RUN apt-get update && apt-get install -y \
libmpfr-dev
# basic shiny functionality
RUN R -e "install.packages(c('shiny', 'rmarkdown'), repos='https://cloud.r-project.org/')"
# install dependencies of the euler app
RUN R -e "install.packages('Rmpfr', repos='https://cloud.r-project.org/')"
# copy the app to the image
RUN mkdir /root/euler
COPY euler /root/euler
COPY Rprofile.site /usr/lib/R/etc/
EXPOSE 3838
CMD ["R", "-e", "shiny::runApp('/root/euler')"]
where specifically does this file have to be written? Where specifically does he have to be saved? what format does it have to be saved?
The pattern I follow is to include the Dockerfile in the root of the project directory.
I also store it in the same repo as the project.
I am trying to deploy my Shiny app on my own server, but I cannot solve this issue. This is my docker image
FROM rocker/tidyverse
## App folder
WORKDIR /home/admin/shinyAppCovid/
ADD /shinyApp /shinyApp/
ADD /dependencias.txt /usr/local/bin/
RUN apt-get update && apt-get install -y \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libssh2-1-dev
# expose port
EXPOSE 8080
# Download and install library
RUN R -e 'install.packages(read.csv("/usr/local/bin/dependencias.txt")[,1], depencencies=TRUE, repos="http://cran.rstudio.com/")'
# run app on container start
CMD ['/usr/bin/R', "-e", "shiny::runApp("/shinyApp/shiny", host = '0.0.0.0', port = 8080)"]
The problem is that when i a try to run a container this is what i have
/bin/sh: 1: [/usr/bin/R,: not found
I changed the last line for jus R and is not working I am still having the same issue, How can I do?
I am dockerizing a shiny app that uses 'mxnet' package. After lots of efforts I concluded that I need to build and install the package instead of just installing it normally from the dmlc repos. Below is me simplified dockerfile that tries to build and install the mxnet:
FROM r-base:latest
RUN apt-get update && apt-get install -y \
sudo \
gdebi-core \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev/unstable \
libxt-dev \
libssl-dev
# Download and install shiny server
RUN wget --no-verbose https://s3.amazonaws.com/rstudio-shiny-server-os- build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
VERSION=$(cat version.txt) && \
wget --no-verbose "https://s3.amazonaws.com/rstudio-shiny-server-os- build/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
gdebi -n ss-latest.deb && \
rm -f version.txt ss-latest.deb
# Here comes the installation of other required packages:
# .......
#*** Here comes the problamatic bit: building Installing mxnet
RUN sudo apt-get update
RUN sudo apt-get install -y build-essential git libatlas-base-dev libopencv-dev
RUN git clone --recursive https://github.com/dmlc/mxnet
RUN cd mxnet; make -j$(nproc)
RUN Rscript -e "install.packages('devtools', repo = 'https://cran.rstudio.com')"
RUN cd R-package
RUN Rscript -e "library('devtools'); library('methods'); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"
RUN cd ..
RUN make rpkg
COPY shiny-server.conf /etc/shiny-server/shiny-server.conf
COPY /myapp/* /srv/shiny-server/
EXPOSE 80
COPY shiny-server.sh /usr/bin/shiny-server.sh
CMD ["/usr/bin/shiny-server.sh"]
After running this, I recieve an error saying:
can not cd to R-Package
Any help?
Try with
RUN cd mxnet; make -j$(nproc)\
&& Rscript -e "install.packages('devtools', repo = 'https://cran.rstudio.com')"
your RUN cd .. will not do what you expect, it is the same as opening a terminal, doing cd abc/def and in another terminal, which is in /home/$USER, doing cd .., you will not be in abc.
You should group your RUN commands in order to limit the number of layers in your image, see
https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
Check also the WORKDIR directive in a Dockerfile
https://docs.docker.com/engine/reference/builder/#workdir
You can check what is correctly done (or not) by launching a shell
docker run -it your_image /bin/bash
and then check what is present or not.