【问题标题】:render() fails to convert .Rmd to .pdf in a containerized Shiny apprender() 无法在容器化 Shiny 应用程序中将 .Rmd 转换为 .pdf
【发布时间】:2018-08-07 14:31:40
【问题描述】:

我正在一个 docker 容器中运行一个闪亮的应用程序。该应用程序从 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

闪亮的服务器日志:

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 会话的容器中,我可以在...knit.md 文件上运行render(),并毫无问题地创建最终的投影仪演示.pdf。只是将*.knit.md 转换为.pdf 并提供下载的最后一步失败了。

当我查看包含我的.Rmd 文件的dir 时,没有.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

这里会发生什么?在完成文件时,似乎所有迹象都应该指向是,但我不知道可能是什么问题。

【问题讨论】:

  • 容器中是否安装了 pandoc。据我所知,knit to pdf 需要它,但不确定这是否能解决问题
  • pandoc 已安装。至少,当我查看pandoc --version 时,我得到了pandoc 1.19.2.1

标签: r docker r-markdown


【解决方案1】:

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

重构我的应用程序以包含两个按钮,一个用于生成报告,一个用于下载报告,这是我的解决方案。这通过允许.Rmd 的编织在downloadHandler() 之外进行,从而绕过了downloadedHandler() 的硬编码超时。

【讨论】:

    猜你喜欢
    • 2017-01-01
    • 2017-01-24
    • 1970-01-01
    • 2020-11-24
    • 2022-08-04
    • 1970-01-01
    • 2011-09-17
    • 2023-03-26
    • 1970-01-01
    相关资源
    最近更新 更多