How to install R packets on a Shiny Server with Kubernetes? - r

I'm trying to publish some panels on Shiny Server with Kubernetes, but I'm struggling with R packets that are not installed on the server.The panels are working on my test environment on AWS (without K8s). The error is below detailed.
> su: ignoring --preserve-environment, it’s mutually exclusive with --login
> Error in library(“shinyWidgets”) :
> there is no package called ‘shinyWidgets’
> Calls: runApp ... sourceUTF8 -> eval -> eval -> ..stacktraceon.. -> library
> Execution halted
As commented in the code, many alternative options to install the R packets were tried without success.
FROM rocker/shiny-verse:latest
USER root
# Finding required libraries. Libraries should be installed in /usr/share/doc
# pak::pkg_system_requirements(“dplyr”, “ubuntu”, “20.04")
# Packects should be installed in /usr/local/lib/R/site-library
# Install system requirements for index.R as needed
RUN apt-get update -qq \
&& apt-get -y --no-install-recommends install \
gdal-bin \
gsfonts \
imagemagick \
libavfilter-dev \
libcurl4-openssl-dev \
libgdal-dev \
libgeos-dev \
libicu-dev \
libjq-dev \
libmagick++-dev \
libnode-dev \
libpng-dev \
libproj-dev \
libprotobuf-dev \
libsqlite3-dev \
libssl-dev \
libudunits2-dev \
make \
protobuf-compiler \
zlib1g-dev \
lbzip2 \
libgeos-c1v5 \
libxml2-dev \
sudo \
pandoc \
pandoc-citeproc \
libcairo2-dev \
libxt-dev \
libssh2-1-dev \
littler \
proj-bin
# Install Tree
RUN apt-get install -y tree
RUN install2.r --error --deps TRUE \
data.table \
dplyr \
geobr \
rgeos \
geojsonio \
ggplot2 \
ggrepel \
ggthemes \
grid \
magick \
magrittr \
pak \
plotly \
png \
readr \
rmapshaper \
shinyBS \
shinycssloaders \
shinyWidgets \
sp \
&& rm -rf /tmp/downloaded_packages
# I also tried to install using these packages with either no success.
# install R packages required
# RUN R -e “install.packages(‘shinyWidgets’, repos=‘http://cran.rstudio.com/’)”
# RUN R -q -e ‘pak::local_install(“shinyWidgets”)’
## assume shiny app is in build folder /shiny
COPY ./cenarios/* /srv/shiny-server/
COPY ./log/shiny-server/ /var/log/shiny-server/
# USER shiny
# allow permission
# RUN sudo chown -R shiny:shiny /srv/shiny-server
# run app
CMD [“/usr/bin/shiny-server”]

Related

Unable to install archive version of WeibullR package on docker

I have created the following dockerfile to deploy an application
# get shiny serves plus tidyverse packages image
FROM rocker/r-ver:latest
RUN apt-get update && apt-get install -y \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libxml2-dev \
libssh2-1-dev
RUN R -e "install.packages('devtools')"
RUN R -e "require(devtools)"
RUN R -e 'install_version("WeibullR", version = "1.1.10", repos="http://cran.us.r-
project.org")'
The build fails. I request someone to guide me. I am unable to get it to work
I have found a solution that works. Am posting the same so that someone could consider it a solution
get shiny server plus tidyverse packages image
FROM rocker/r-ver:latest
FROM rocker/shiny-verse:latest
RUN apt-get update && apt-get install -y \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libxml2-dev \
libssh2-1-dev
RUN R -e "install.packages('devtools')"
RUN R -e "require(devtools)"
RUN R -e 'install_version("WeibullR", version = "1.1.10",
repos="http://cran.us.r-
project.org")'
This works neatly.

Docker can't find leaflet when deploying r shiny app

I've seen a few other posts about the same issue, but no clear solution from any of them.
When running docker build -t test-shiny ., I get the following error when running the docker image locally:
Error in library(leaflet) : there is no package called ‘leaflet’
Calls: <Anonymous> ... sourceUTF8 -> eval -> eval -> ..stacktraceon.. -> library
Execution halted
Here is my Dockerfile:
# Base image https://hub.docker.com/u/rocker/
FROM rocker/r-base:latest
RUN apt-get update && apt-get -y --no-install-recommends install \
curl \
wget \
sudo \
alien \
redis-server \
gnupg \
unixodbc-dev && \
rm -rf /var/lib/apt/lists/* && \
apt-get clean
RUN apt-get update && apt-get -y --no-install-recommends install \
libpng-dev \
libudunits2-dev \
libgeos-dev \
libproj-dev \
libssl-dev \
libcurl4-openssl-dev \
libhiredis-dev \
libmagick++-dev && \
rm -rf /var/lib/apt/lists/* && \
apt-get clean \
libgdal-dev \
netcdf-bin
# Athena ODBC Drivers
RUN wget https://s3.amazonaws.com/athena-downloads/drivers/ODBC/SimbaAthenaODBC_1.1.9.1001/Linux/simbaathena-1.1.9.1001-1.el7.x86_64.rpm && \
sudo alien -i simbaathena-1.1.9.1001-1.el7.x86_64.rpm && \
rm simbaathena-1.1.9.1001-1.el7.x86_64.rpm
# Dependencies
RUN Rscript -e 'install.packages(c("shiny", "shinydashboard", "ggplot2", "patchwork","dbplyr", "dbplot", "scales", "shinycssloaders", "rJava", "RJDBC", "shinyjs", "shinyBS", "highcharter", "leaflet", "DT", "glue", "DBI", "odbc", "data.table"), dependencies = TRUE, repos="http://cran.rstudio.com/", Ncpus=5)' && rm -rf /tmp/downloaded_packages
# Copy App
RUN mkdir shiny-app
COPY evaluation-app/ /shiny-app
# RShiny Port
EXPOSE 3838
# Run App
CMD ["R", "-e", "shiny::runApp('/shiny-app', host = '0.0.0.0', port = 3838)"]
I know I am installing a lot of r packages, but my app runs fine in RStudio. After reading this post, I already tried adding the solution from the accepted answer, but unsuccessful. Any suggestions or solutions would be much appreciated.

unexpected symbol in "install.packages(RODBC_1.2-6.tar.gz" when running in a dockerfile

I'm trying to install an old version of RODBC into my dockerfile (I'm using R 3.6.3 and the newest version of RODBC needs R v4) by downloading the package using curl and then installing using install.packages but I'm getting the below error. Any ideas of how to achieve this?
Error: unexpected symbol in "install.packages(RODBC_1.2-6.tar.gz"
In the dockerfile I try to do the above with the following RUN statements:
RUN curl https://cran.r-project.org/src/contrib/Archive/RODBC --output RODBC_1.2-6.tar.gz
RUN R -e "install.packages(RODBC_1.2-6.tar.gz)"
The full dockerfile is:
FROM ubuntu:bionic
RUN useradd docker \
&& mkdir /home/docker \
&& chown docker:docker /home/docker \
&& addgroup docker staff
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
software-properties-common \
ed \
less \
locales \
vim-tiny \
wget \
ca-certificates \
&& add-apt-repository --enable-source --yes "ppa:marutter/rrutter3.5" \
&& add-apt-repository --enable-source --yes "ppa:marutter/c2d4u3.5"
## Configure default locale, see https://github.com/rocker-org/rocker/issues/19
RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen en_US.utf8 \
&& /usr/sbin/update-locale LANG=en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
littler \
r-base \
r-base-dev \
r-recommended \
&& ln -s /usr/lib/R/site-library/littler/examples/install.r /usr/local/bin/install.r \
&& ln -s /usr/lib/R/site-library/littler/examples/install2.r /usr/local/bin/install2.r \
&& ln -s /usr/lib/R/site-library/littler/examples/installGithub.r /usr/local/bin/installGithub.r \
&& ln -s /usr/lib/R/site-library/littler/examples/testInstalled.r /usr/local/bin/testInstalled.r \
&& install.r docopt \
&& rm -rf /tmp/downloaded_packages/ /tmp/*.rds \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update
#These are all required, the exact version, for SQL Server to work
RUN apt-get install -y gnupg2 libssl1.0 libssl1.0-dev apt-transport-https
RUN apt-get install -y libcurl4-openssl-dev curl
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17 unixodbc unixodbc-dev
RUN apt-get install -y libssl-dev
RUN install.r tidyr bigrquery dplyr sqldf readr httr uuid
RUN curl https://cran.r-project.org/src/contrib/Archive/RODBC --output RODBC_1.2-6.tar.gz
RUN R -e "install.packages(RODBC_1.2-6.tar.gz)"
COPY src/upload_v2.r /usr/local/src/scripts/upload_v2.r
WORKDIR /usr/local/src/scripts
It looks like quote is missing in RUN R line:
RUN curl https://cran.r-project.org/src/contrib/Archive/RODBC --output RODBC_1.2-6.tar.gz
RUN R -e "install.packages('RODBC_1.2-6.tar.gz')"

How to silently install r-base in an ubuntu docker image

I need to install r-base within an ubuntu:18.04 dockerimage. I am doing this while building my image via
RUN apt-get update; apt-get install -y r-base [many other packages]
along with many other package installations. The problem is, that while setting up r-base at the end of the installation process, it asks for user input for timezone followed by city within the specified timezone. I obviously cannot enter the data while building the container. How would I manage to install r-base anyways?
From AskUbuntu, you should set
ENV DEBIAN_FRONTEND=noninteractive
Directly taken from: https://github.com/rocker-org/rocker/blob/master/r-ubuntu/Dockerfile
FROM ubuntu:bionic
LABEL org.label-schema.license="GPL-2.0" \
org.label-schema.vcs-url="https://github.com/rocker-org/r-apt" \
org.label-schema.vendor="Rocker Project" \
maintainer="Dirk Eddelbuettel <edd#debian.org>"
## Set a default user. Available via runtime flag `--user docker`
## Add user to 'staff' group, granting them write privileges to /usr/local/lib/R/site.library
## User should also have & own a home directory (for rstudio or linked volumes to work properly).
RUN useradd docker \
&& mkdir /home/docker \
&& chown docker:docker /home/docker \
&& addgroup docker staff
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
software-properties-common \
ed \
less \
locales \
vim-tiny \
wget \
ca-certificates \
&& add-apt-repository --enable-source --yes "ppa:marutter/rrutter3.5" \
&& add-apt-repository --enable-source --yes "ppa:marutter/c2d4u3.5"
## Configure default locale, see https://github.com/rocker-org/rocker/issues/19
RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen en_US.utf8 \
&& /usr/sbin/update-locale LANG=en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
## This was not needed before but we need it now
ENV DEBIAN_FRONTEND noninteractive
# Now install R and littler, and create a link for littler in /usr/local/bin
# Default CRAN repo is now set by R itself, and littler knows about it too
# r-cran-docopt is not currently in c2d4u so we install from source
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
littler \
r-base \
r-base-dev \
r-recommended \
&& ln -s /usr/lib/R/site-library/littler/examples/install.r /usr/local/bin/install.r \
&& ln -s /usr/lib/R/site-library/littler/examples/install2.r /usr/local/bin/install2.r \
&& ln -s /usr/lib/R/site-library/littler/examples/installGithub.r /usr/local/bin/installGithub.r \
&& ln -s /usr/lib/R/site-library/littler/examples/testInstalled.r /usr/local/bin/testInstalled.r \
&& install.r docopt \
&& rm -rf /tmp/downloaded_packages/ /tmp/*.rds \
&& rm -rf /var/lib/apt/lists/*
CMD ["bash"]

Why is remoter not working when I enable encryption?

I'm trying to connect to a remoter server and getting the following error:
Error in sodium::auth_decrypt(encrypted, getkey(private), getkey(theirs)) :
is.raw(nonce) is not TRUE
In addition: Warning message:
In unserialize(rmsg) :
cannot unserialize ALTVEC object of class 'wrap_raw' from package 'base'; returning length zero vector
If I run the server with secure = FALSE everything works as expected. This is the dockerfile that i'm using to run the server:
FROM rocker/r-ubuntu:18.04
# Install dependencies
RUN apt-get update -qq && apt-get install -y \
libsodium-dev \
libxml2-dev \
libssl-dev \
libcurl4-openssl-dev \
r-cran-tidyverse \
r-cran-remotes \
r-cran-rstan \
r-cran-rstanarm \
r-cran-rstan \
&& install.r \
remoter \
sodium \
drat \
RcppArmadillo \
RcppEigen \
StanHeaders \
aws.signature \
aws.s3
COPY R/Makevars /root/.R/Makevars
RUN mkdir -p /root/.ssh
VOLUME [ "/root/.ssh" ]
CMD ["R", "-e", "remoter::server(port = 49152, secure = T, password=Sys.getenv('api_key'))"]
Is this a bug in the remoter package or am I doing something wrong?

Resources