【发布时间】:2020-03-04 12:21:49
【问题描述】:
我有一个使用 Docker 容器化的闪亮应用程序。在闪亮的应用程序中,我使用shinyFiles 库来允许用户选择和上传目录。
我的 server.R 文件如下所示:
shinyServer(function(input, output, clientData, session) {
volumes <- c("Home (~)" = '~', "Current directory" = getwd(), "Root (/)" = '/')
shinyDirChoose(input, 'resultsLocation', roots=volumes, session=session)
})
我的 ui.R 文件看起来像这样:
library(shiny)
library(shinyFiles)
shinyUI(fluidPage(
shinyDirButton('resultsLocation', 'Browse...', title = 'Select a directory')
))
如果我通过 R 在本地运行应用程序,这很好,但是,如果我构建并运行 docker 容器,用户将无法访问其本地卷,而是卡在 docker 容器中。
我按照 this 指南设置了我的 docker 容器(添加了运行 chmod +x shiny-server.sh 以使文件可执行)并且卷以外的所有内容都在工作。我的 Dockerfile 看起来像这样:
# 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"]
我构建并运行容器:
docker build -t shiny_docker_test . ; docker run -p 3838:3838 shiny_docker_test
所以,我的问题是:如何通过带有 shinyFiles 的 dockerised shiny 应用程序访问我的本地文件系统/卷?我确信有一个简单的解决方案,但我对所有这些东西都不熟悉。
【问题讨论】:
标签: r docker shiny dockerfile