Permission denied with shiny::bindCache() - Trying to set up persistent cache on docker container

I am having issues with permission being denied when trying to use a persistent cache with the new bindCache() function. Everything works perfectly fine on my own computer, but when I build it with docker the plot does not show up and I get the following error:

cannot open compressed file '/srv/shiny-server/plot-cache/c0e050396e438974429673dba2aad4e4.rds-temp-389d897bab8657c8', probable reason 'Permission denied'

Warning: Error in cache$set: Error setting value for key "c0e050396e438974429673dba2aad4e4".

I am using the following in my server.R file:

output$plot <- renderPlot({plot_here }) %>% 
      shiny::bindCache(input$cloud_n, Text_Data()
                      # If the line below this is commented out, the default behavior works well
                       , cache = cachem::cache_disk("./plot-cache")

My dockerfile looks something like this:

FROM rocker/shiny:4.0.3

LABEL org.label-schema.license="GPL-2.0" \
      org.label-schema.vcs-url="" \
      org.label-schema.vendor="Rocker Project" \
      maintainer="Carl Boettiger <>"

RUN /rocker_scripts/
RUN /rocker_scripts/

# Install R packages that are required
RUN R -e "install.packages('shinydashboard')"
RUN R -e "install.packages('leaflet')"
RUN R -e "install.packages('DT')"
RUN R -e "install.packages('pdp')"
RUN R -e "install.packages('randomForest')"
RUN R -e "install.packages('wordcloud')"
# Added this to insure I get the latest shiny with bindCache()
RUN R -e "install.packages('shiny')"

COPY /App /srv/shiny-server/

Is there a way to set the permissions in my dockerfile to give my app the permission it needs to write files in the persistent cache folder?

If not in the dockerfile, is there some other way to specify permissions for the cache folder? Maybe a simple shell script that is run in the dockerfile? I am not sure the best way to go about this. I found this about shiny file permissions but I do not know how to implement for my use case. Thanks!

The /srv/shiny-server/ directory is probably not writable by the user that the Shiny application is running as.

I don't know exactly how Shiny Server is configured on your system, but I think you'll need to change the owner or permissions of /srv/shiny-server and/or change which user the application is running as.

Another alternative is to create a subdirectory in the system temp directory and use that for the cache.

1 Like

Based on the update at the bottom of this page I can replace the last line of my dockerfile with:

COPY --chown=shiny:shiny /App /srv/shiny-server/

I tested this and it seems to work properly now. Does this have any negative consequences like making the app less secure? Is making a subdirectory in the temp directory a better solution? Thank you for your input!

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.