Dockerized flexdashboard 应用程序不会在本地主机中 运行

Dockerized flexdashboard app won't run in localhost

我正在尝试创建一个 Docker 化的 Flexdashboard 应用程序。我可以在本地 运行 它,但不能在本地主机中。 但是,我可以在同一张 docker 图像中 运行 闪亮的应用程序。有趣的是,本地主机中的错误消息显示 Flexdashboard 应用程序 'Not Found',这与页面根本不存在时 ('Page Not Found').

不同

如何 Docker 化 Flexdashboard 应用程序?

MWE

dir.create("testshinydocker")
dir.create("testshinydocker/apps")
dir.create("testshinydocker/apps/kmeans")
dir.create("testshinydocker/apps/kmeansflex")

cat(readLines("https://raw.githubusercontent.com/rstudio/shiny-examples/master/050-kmeans-example/server.R"),
    file = "testshinydocker/apps/kmeans/server.R", sep = "\n")

cat(readLines("https://raw.githubusercontent.com/rstudio/shiny-examples/master/050-kmeans-example/ui.R"),
    file = "testshinydocker/apps/kmeans/ui.R", sep = "\n")

cat(
  c('FROM rocker/shiny:latest\n',

  "RUN  echo 'install.packages(c(\"flexdashboard\"), \",
  "repos='$MRAN', \",
  "dependencies=TRUE)' > /tmp/packages.R \",
  "  && Rscript /tmp/packages.R\n",

  'EXPOSE 3838\n',
  'COPY apps /srv/shiny-server/\n',
  'CMD ["/usr/bin/shiny-server.sh"]\n'),
  file = "testshinydocker/Dockerfile",
  sep = "\n"
)

cat(readLines("https://raw.githubusercontent.com/rstudio/flexdashboard/master/examples/11_shiny-kmeans-clustering/dashboard.Rmd"),
    file = "testshinydocker/apps/kmeansflex/kmeans2.Rmd", sep = "\n")

shiny::runApp('testshinydocker/apps/kmeans')

rmarkdown::run("testshinydocker/apps/kmeansflex/kmeans2.Rmd")

Docker 代码(运行 在 Powershell 中)

cd {path to testshinydocker directory}
docker build -t myapp .
docker run --rm -d -p 3838:3838 myapp

本地主机网址

闪亮的应用程序有效

Flexdashbord 应用程序 'Not Found'

不存在的恐龙页面'Page not Found'

这可能是您的图像中使用的 rmarkdown 包中存在错误的结果 (rmoarkdown v. 1.18),并且与此相关:https://github.com/rstudio/rmarkdown/issues/1731 and https://github.com/rstudio/rmarkdown/issues/1714. I'm guessing http://localhost:3838/kmeansflex/kmeans2.Rmd 确实有效。

下面是测试方法。在 apps 文件夹中制作一个闪亮的应用程序,以查看正在使用哪个版本的 rmarkdown 运行。在 apps 中创建一个名为 'rmarkdown' 的文件夹。然后放下面简单的ui.Rserver.R 脚本用于构建闪亮的应用程序(我们知道闪亮的应用程序会为您呈现)以确定您拥有的 rmarkdown 版本:

ui.R 脚本

fluidPage( 
  hr(),
  fluidRow(column(3, verbatimTextOutput("value")))   
)

server.r 脚本

function(input, output) {
​  output$value <- renderPrint({ utils::packageVersion('rmarkdown') })
}

然后 docker build 并重新 docker run 并在浏览器中转到 http://localhost:3838/rmarkdown/。它应该带您到屏幕并显示您拥有的 rmarkdown 版本。如果是 1.18 那就是罪魁祸首。

可能的解决方案

如果 rmarkdown 安装的是 1.18 版本,一个可能的解决方案是从 github 安装 rmarkdown 在你的 Dockerfile 中,这样你就可以得到一个没有这个的更新版本错误,一切都很好。这是您的 Dockerfile 中的样子:

FROM rocker/shiny:latest

# apt-get and system utilities
RUN apt-get update && apt-get install -y \
    libssl-dev \
    libsodium-dev

RUN  echo 'install.packages(c("flexdashboard", "remotes", "openssl"), \
repos='$MRAN', \
dependencies=TRUE)' > /tmp/packages.R \
  && Rscript /tmp/packages.R

RUN Rscript -e 'remotes::install_github("rstudio/rmarkdown")' 

COPY apps /srv/shiny-server/


EXPOSE 3838

CMD ["/usr/bin/shiny-server.sh"]