Search code examples
rdockershinydockerfilergdal

Unable to dockerize a RStudio Shiny project, error with package rgdal


I am trying to dockerize a shiny project and am having getting an error when running the docker image:

Error: package or namespace load failed for ‘rgdal’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/local/lib/R/site-library/rgdal/libs/rgdal.so':
  libgdal.so.26: cannot open shared object file: No such file or directory

For context my file structure is as follows:

.
├── shiny-app
│   ├── App.R
│   └── data
├── .gitignore
├── Dockerfile
├── README.md
└── my-project.Rproj

My shiny-app has the following library dependencies:

library(shiny)
library(shinythemes)
library(textdata)
library(tidyverse)
library(leaflet)
library(rgdal)
library(viridis)

(I know I could defiantly narrow down the dependency size by selecting only the packages within tidyverse that I am using but that's a problem for later).

Finally, my Dockerfile contains the following commands:

# get shiny server and R from the rocker project
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 /shiny-app ./app

# install R packages required 
RUN R -e 'install.packages(c(\
              "shiny", \
              "shinythemes", \
              "textdata", \
              "tidyverse", \
              "rgdal", \
              "leaflet", \
              "viridis", \
            ), \
            repos="https://packagemanager.rstudio.com/cran/__linux__/focal/2021-04-23"\
          )'


# run app on container start
CMD ["R", "-e", "shiny::runApp('/app')"]

I am able to build the image with docker build -t my-app .. However, when I try to run the docker image I get the error as I mentioned above. The weirdest part though is that shiny, tidyverse, and other packages are able to load. I am not sure why, then, docker is unable to access and use the installed package of rgdal if it can access the others.

Would love to hear any ideas! Thanks!


Solution

  • rgdal needs the following installed in Linux:

    libgdal-dev libproj-dev