【问题标题】:Dockerized flexdashboard app won't run in localhostDockerized flexdashboard 应用程序不会在 localhost 中运行
【发布时间】:2020-06-24 15:46:54
【问题描述】:

我正在尝试创建一个 Dockerized Flexdashboard 应用程序。我可以在本地运行它,但不能在本地主机中运行。 但是,我可以在同一个 docker 映像中运行闪亮的应用程序。有趣的是,本地主机中的错误消息显示 Flexdashboard 应用程序的“未找到”,这与页面根本不存在时不同(“未找到页面”)。

如何 Dockerize 一个 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

本地主机 URL

闪亮的应用工作

Flexdashbord 应用“未找到”

不存在的恐龙页面“找不到页面”

【问题讨论】:

  • 嗯,我运行了你的确切代码,可以看到 http://localhost:3838/kmeansflex 应用程序。
  • 谢谢@TylerRinker - 我真的被这个难住了。我怀疑这是我个人机器上的设置问题,希望有人对此有经验。

标签: r docker shiny flexdashboard


【解决方案1】:

这可能是由于您的图像中使用的 rmarkdown 包中的错误(rmoarkdown v. 1.18)造成的,并且与此相关:https://github.com/rstudio/rmarkdown/issues/1731https://github.com/rstudio/rmarkdown/issues/1714。我猜http://localhost:3838/kmeansflex/kmeans2.Rmd 确实有效。

您可以通过以下方式进行测试。在应用程序文件夹中创建一个闪亮的应用程序,以查看正在运行的 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 版,则可能的解决方案是在 Dockerfile 中从 github 安装 rmarkdown,这样您就可以获得没有此错误的更新版本,一切都很好。这是 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"]

【讨论】:

    猜你喜欢
    • 2017-11-20
    • 2021-09-20
    • 2020-02-04
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 2012-05-27
    • 2010-10-18
    • 2017-11-22
    相关资源
    最近更新 更多