How can i dockerize my shinyapp with multiple packages (packages not recognized)

First of all, i'm a newbie in the docker world.

I have a problem with running a docker image with my shiny app. Usually, i use R-Studio in Windows, and my shiny apps works fine with "Run App" my app.R file.

First of all, i have to say i use this tuto and with a simple shiny app version, it works great.

But with my app, which has a lot of packages, and i imagine a lot of dependancies between them, it doesn't. When i go to my browser on localhost, i have this message : 'An error has occurred .The application failed to start. The application exited during initialization'.

Looking the .log files, i have this kind of warning (i have the same messages on R-Studio) :

 Attaching package: ‘DT’

    The following objects are masked from ‘package:shiny’:
    
        dataTableOutput, renderDataTable
    
    
    Attaching package: ‘dplyr’
    
    The following objects are masked from ‘package:stats’:
    
        filter, lag

I'm not very worried about that (even if i suppose i can do better and delete some dependancies), but my main problem is, i suppose here :

.....
**Error in library(tm) : there is no package called ‘tm’
Calls: runApp ... sourceUTF8 -> eval -> eval -> ..stacktraceon.. -> library
Execution halted
su: ignoring --preserve-environment, it's mutually exclusive with --login**

.....

It seems some packages can't be installed on the R version in dockerfile.
I don't understand that cause i'm using R 3.5.3 in Windows and i put R 3.5.3 on the dockerfile.

I build another container with deleting this tm package on dockerfile and the "library(tm)" on my app.R, running this new image... and the next error message from the log file was "library(magick) : there is no package called ‘magick'" and so on... At least 3 packages can't be read.

Here is my entire dockerfile :

# Install R version 3.5.3
FROM r-base:3.5.3

# Install Ubuntu packages
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 ShinyServer (latest version)
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

# Install R packages that are required
# TODO: add further package if you need!
RUN R -e "install.packages(c('shiny','readxl','stringr','DT','plyr','dplyr','ggplot2','plotly','scales','magrittr','rclipboard','shinythemes','Rmisc','data.table','qmap','wordcloud2','stringi','radarchart','leaflet','forcats','timevis','shinyWidgets','XLConnect','XLConnectJars','shinyalert','shinyjs','sqldf','sodium','glue','V8','lubridate'), repos='http://cran.rstudio.com/')"

# Copy configuration files into the Docker image
COPY shiny-server.conf  /etc/shiny-server/shiny-server.conf
COPY /app /srv/shiny-server/

# Make the ShinyApp available at port 80
EXPOSE 80

# Copy further configuration files into the Docker image
COPY shiny-server.sh /usr/bin/shiny-server.sh

CMD ["/usr/bin/shiny-server.sh"]

As you can see, i have a lot of packages to install, i imagine a lot of depencies between them, can be bad.

Here is my shiny-server.conf file :

access_log /var/log/shiny-server/access.log tiny;
preserve_logs true;

# Define the user we should use when spawning R Shiny processes
run_as shiny;

# Define a top-level server which will listen on a port
server {
  # Instruct this server to listen on port 80. The app at dokku-alt need expose PORT 80, or 500 e etc. See the docs
  listen 80;

  # Define the location available at the base URL
  location / {

    # Run this location in 'site_dir' mode, which hosts the entire directory
    # tree at '/srv/shiny-server'
    site_dir /srv/shiny-server;
    
    # Define where we should put the log files for this location
    log_dir /var/log/shiny-server;
    
    # Should we list the contents of a (non-Shiny-App) directory when the user 
    # visits the corresponding URL?
    directory_index on;
  }
}

And finally my shiny-server.sh file :

#!/bin/sh

# Make sure the directory for individual app logs exists
mkdir -p /var/log/shiny-server
chown shiny.shiny /var/log/shiny-server

exec shiny-server >> /var/log/shiny-server.log 2>&1

My app folder contains my app.R file and some excels (some massive excels files), maybe it can be a bad factor...

Thanks in advance for your help

I don't have experience deploying shiny apps in docker containers but I have some thoughts about your issue:

To handle some of the R package dependencies, you can use dependencies = TRUE in your call to install.packages().

Besides the R package dependencies you also have to consider the system dependencies, for example, magick package requires that you have installed libmagick in your system

sudo apt-get install libmagick++-dev

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.