'Cache data in Shiny Server on Docker

I am currently trying to implement caching on my dockerized shiny app, but i am facing troubles, the app doesn't work and there's no log to trace the problem: Screenshot from the dockerized app

I am using the rocker/shiny image, installing a few R packages (via the packages.R file) above and then running my shiny-app.

Here is a piece of my docker-compose.yml:

services:
  shiny:
    build: 'shiny-app/.'
    volumes:
      - ./shiny-app/:/srv/shiny-server/
      - ./data/:/home/project/data/
    ports:
      - '3838:3838'

My Dockerfile for the corresponding Shiny app is:

FROM rocker/shiny:latest
ADD . /srv/shiny-server/
RUN apt-get update
RUN apt-get install -y libssl-dev
RUN Rscript /srv/shiny-server/packages.R
EXPOSE 3838
CMD ["/usr/bin/shiny-server.sh"]

In my app (server.R), i am using the DataCache library (https://github.com/jbryer/DataCache) as follows:

library(Datacache)

load_data <- function() {
  MyData <- data.table::fread("/Users/toto/projects/data/N201801.csv")
}
DataCache::data.cache(load_data)

function(input, output) {
 # Load data ------------------------
  load_data()
 # Other treatments...
})

It works perfectly on my computer using RStudio: Shiny creates a cache folder containing a .rda file which is the cached data.

Nevertheless, it doesn't work on the dockerized application.

Has someone ever encountered this problem ?

Thank you in advance,

Alexandre



Solution 1:[1]

System user Shiny runs your shiny app. Check if user Shiny has the permission to write within srv/shiny-server. If not, the app run by user Shiny won't be able to write anything and the app would just crash without a error message.

You can set the user permission in the docker file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pacman