我正在Docker容器中运行Shiny应用程序。该应用程序从Google Analytics(分析)中提取/处理数据,然后将这些数据传递到.Rmd文件中,然后将该文件编织到投影仪演示文稿中,然后提供该文件以供下载。 docker镜像正在使用R v3.4.4.运行rmarkdown v1.10。该应用程序可以正常工作,除了最后一步,在此过程中,我使用render().Rmd编织为.pdf
pdflatex已安装并可以在我的容器中访问:

root@de4bd1ee457a:/# pdflatex
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdflatex)
 restricted \write18 enabled.

我的sessionInfo()
> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.19.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.4.4

Shiny 的服务器日志:
Listening on http://127.0.0.1:45211
2018-08-07 13:49:19> No scopes have been set, set them via
options(googleAuthR.scopes.selected) -
  no authentication attempted.

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

  filter, lag

The following objects are masked from ‘package:base’:

  intersect, setdiff, setequal, union

2018-08-07 13:49:20> Default Google Project for googleAnalyticsR is now set.
This is shared with all googleAnalyticsR users.
If making a lot of API calls, please:
  1) create your own Google Project at https://console.developers.google.com
2) Activate the Google Analytics Reporting API
3) set options(googleAuthR.client_id) and options(googleAuthR.client_secret)
4) Reload the package.
2018-08-07 13:49:20> Set API cache
2018-08-07 13:49:20> No environment argument found, looked in GA_AUTH_FILE

Attaching package: ‘jsonlite’

The following object is masked from ‘package:shiny’:

  validate

2018-08-07 13:49:36> Downloaded [5045] rows from a total of [5045].


processing file: GA_report.Rmd
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
output file: GA_report.knit.md

我已经验证成功创建了GA_report.knit.md(以及.Rmd文件中的所有数字)。在R session 的容器中,我可以在render()文件上运行...knit.md并创建最终的投影仪演示.pdf,而不会出现问题。只是将*.knit.md转换为.pdf并提供下载的最后一步失败了。

当我查看包含我的dir文件的.Rmd时,没有.tex文件,只有GA_report.knit.mdGA_report.utf8.md

我的.Rmd的标题
---
output:
  beamer_presentation:
    theme: "SwCustom"
title: "`r paste0('Draft report: ', params$client)`"
date: "`r Sys.Date()`"
toc: FALSE
classoption: aspectratio=169
editor_options:
  chunk_output_type: console
params:
  data: NA
  client: NA
---
render()语句
render("report/GA_report.Rmd",
       output_format = "all",
       output_file = file,
       params = params,
       envir = new.env(parent = globalenv()),
       clean = FALSE,
       quiet = FALSE)

我的自定义投影仪主题可在容器中访问
root@de4bd1ee457a:/# kpsewhich beamerthemeSwCustom.sty
/opt/TinyTeX/texmf-dist/tex/latex/beamer/beamerthemeSwCustom.sty

这可能是怎么回事?在完成文件过程中,似乎所有迹象都应指向是,但是我对可能的问题感到困惑。

最佳答案

我相信这与Shiny Server中的最大超时错误有关。我的Docker容器正在运行Shiny Server,并且this issue on the Shiny Server github建议在Shiny Server中的downloadHandler()中存在硬编码的超时。由于我的.Rmd文件很大,因此转换为.pdf所需的时间比自动超时要长得多。因为downloadHandler()从未提供我期望的下载内容,所以我将取消该过程,并且最终.pdf从未创建。

重构我的应用程序以使其包括两个按钮,一个用于生成报告,一个用于下载报告。通过允许在downloadedHandler()之外进行.Rmd的编织,避免了downloadHandler()的硬编码超时。

关于r - render()无法在容器化的Shiny应用中将.Rmd转换为.pdf,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51729323/

10-12 19:47