Reputation: 231
I have a shiny application which I have containerised with Docker. Within the shiny application I use the shinyFiles
library to allow the user to choose and upload a directory.
My server.R file looks something like this:
shinyServer(function(input, output, clientData, session) {
volumes <- c("Home (~)" = '~', "Current directory" = getwd(), "Root (/)" = '/')
shinyDirChoose(input, 'resultsLocation', roots=volumes, session=session)
})
and my ui.R file looks something like this:
library(shiny)
library(shinyFiles)
shinyUI(fluidPage(
shinyDirButton('resultsLocation', 'Browse...', title = 'Select a directory')
))
This is fine if I run the app locally through R, however, if I build and run the docker container, the user cannot access their local volumes, and instead are stuck within the docker container.
I followed this guide to set up my docker container (with the addition of running chmod +x shiny-server.sh
to make the file executable) and everything other than the volumes is working. My Dockerfile looks like this:
# Install R version 3.6.0
FROM r-base:3.6.0
# 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
RUN R -e "install.packages('shiny')"
RUN R -e "install.packages('shinyFiles')"
# 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 3838
# EXPOSE 3838
# Copy further configuration files into the Docker image
COPY shiny-server.sh /usr/bin/shiny-server.sh
# Allow permissions
RUN chown -R shiny:shiny /srv/shiny-server
CMD ["/usr/bin/shiny-server.sh"]
And I build and run the container with:
docker build -t shiny_docker_test . ; docker run -p 3838:3838 shiny_docker_test
So, my question is: how can I access my local filesystem/volumes through the dockerised shiny app with shinyFiles? I'm sure there is a simple solution, but I am new to all of this stuff.
Upvotes: 0
Views: 1130
Reputation: 1733
Use docker volume feature. For example: In command line -v is used to map container directories with host directories
docker -v full_path_on_host:full_path_inside_container
Similarly, there is VOLUME keyword for same stuff while working on docker file.
Upvotes: 1