Agr*_*sel 6 r shiny docker dockerfile
我目前正在尝试构建一个大型 Docker 映像并从中运行一个闪亮的应用程序,以便最终可以将其部署到 Unix 服务器。镜像构建成功;但是,当我去运行图像时,应用程序会运行并完全忽略指定的端口。
更奇怪的是,我首先构建了一个小型测试应用程序,并且这篇 SO 帖子(Shiny app docker 容器未在浏览器中加载)中的说明有效。我将测试应用程序中使用的相同样式复制到另一个 Shiny 应用程序中,但现在它不起作用。
我的 Docker 镜像的结构与 ShinyProxy 在其 Github 页面上使用的结构类似: https: //github.com/openanalytics/shinyproxy-template:
|-- Dockerfile
|-- Rprofile.site
|-- app_stuff
|-- app.R
|-- accessory files called from app.R...
Run Code Online (Sandbox Code Playgroud)
我的Dockerfile如下:
# Install R version 3.5.1
FROM r-base:3.5.1
# system libraries of general use - I don't know if these are right ????
RUN apt-get update && apt-get install -y \
default-jdk \
libbz2-dev \
zlib1g-dev \
gfortran \
liblzma-dev \
libpcre3-dev \
libreadline-dev \
xorg-dev \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libssh2-1-dev \
libxml2-dev
RUN R -e "install.packages('remotes');"
RUN R -e "library(remotes); \
remotes::install_version('shiny', version='1.1.0', repos='https://cran.r-project.org/'); \
remotes::install_version('tidyverse', version='1.2.1', repos='https://cran.r-project.org/'); \
remotes::install_version('ggiraph', version='0.6.0', repos='https://cran.r-project.org/'); \
remotes::install_version('plotly', version='4.8.0', repos='https://cran.r-project.org/'); \
remotes::install_version('CausalImpact', version='1.2.3', repos='https://cran.r-project.org/'); \
remotes::install_version('reshape2', version='1.4.3', repos='https://cran.r-project.org/'); \
remotes::install_version('bsts', version='0.8.0', repos='https://cran.r-project.org/'); \
remotes::install_version('xts', version='0.10-2', repos='https://cran.r-project.org/'); \
remotes::install_version('BoomSpikeSlab', version='1.0.0', repos='https://cran.r-project.org/'); \
remotes::install_version('Boom', version='0.8', repos='https://cran.r-project.org/'); \
remotes::install_version('MASS', version='7.3-50', repos='https://cran.r-project.org/'); \
remotes::install_version('dygraphs', version='1.1.1.4', repos='https://cran.r-project.org/'); \
remotes::install_version('prophet', version='0.4', repos='https://cran.r-project.org/'); \
remotes::install_version('rlang', version='0.3.3', repos='https://cran.r-project.org/'); \
remotes::install_version('Rcpp', version='1.0.1', repos='https://cran.r-project.org/'); \
remotes::install_version('zoo', version='1.8-1', repos='https://cran.r-project.org/'); \
remotes::install_version('RJDBC', version='0.2-7.1', repos='https://cran.r-project.org/'); \
remotes::install_version('rJava', version='0.9-10', repos='https://cran.r-project.org/'); \
remotes::install_version('shinyjs', version='1.0', repos='https://cran.r-project.org/'); \
remotes::install_version('DT', version='0.5', repos='https://cran.r-project.org/'); \
remotes::install_version('shinyBS', version='0.61', repos='https://cran.r-project.org/');"
# copy the app to the image
RUN mkdir /root/app_stuff
COPY app_stuff /root/app_stuff
COPY Rprofile.site /usr/lib/R/etc/
EXPOSE 3838
CMD ["R", "-e", "shiny::runApp('/root/app_stuff')"]
Run Code Online (Sandbox Code Playgroud)
我的Rprofile.site是:
local({
options(shiny.port = 3838, shiny.host = "0.0.0.0")
})
Run Code Online (Sandbox Code Playgroud)
使用命令构建文件后
docker build -t price_opt .
Run Code Online (Sandbox Code Playgroud)
然后运行图像
docker run -it -p 3838:3838 price_opt
Run Code Online (Sandbox Code Playgroud)
我原本希望看到闪亮的应用程序打印出:Listening on http://0.0.0.0:3838
,但它却打印出:
Listening on http://127.0.0.1:6688
Run Code Online (Sandbox Code Playgroud)
我在本地计算机上找不到它。
同样,最奇怪的是这种类型的设置适用于较小的闪亮应用程序。当我在较小的应用程序上从上面运行该docker run
命令时,该应用程序在 localhost:3838 下可用。
对于为什么会发生这种情况有什么想法吗?我的最后一件事是,Shiny Proxy 网站上的这个用户似乎也有类似的问题(https://support.openanalytics.eu/t/shiny-app-listening-on-wrong-host/957)。他的问题是某种拼写错误,但它似乎确实以同样的方式起作用,其中 Shiny 应用程序完全忽略 Rprofile.site 和命令中提供的端口号docker run
。
感谢用户@Wil,通过将 Dockerfile 的最后一行更改为CMD ["R", "-e", "shiny::runApp('/root/app_stuff', host='0.0.0.0', port=3838)"]
,应用程序能够在 localhost:3838 上正常启动。
端口 3838 是 Shiny Server 的默认端口,但runApp()
需要选择一个可用端口。看起来 R 没有接收到您的Rprofile.site
,所以我只需在您的调用中指定端口runApp()
:
CMD ["R", "-e", "shiny::runApp('/root/app_stuff',options = list(port = '3838'))"]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1774 次 |
最近记录: |