Steven
Steven

Reputation: 3292

render() fails to convert .Rmd to .pdf in a containerized Shiny app

I'm running a Shiny app in a docker container. The app pulls/handles data from Google Analytics, passes those data into an .Rmd file, knits the file into a beamer presentation, then offers that file for download. The docker image is running R v3.4.4. with rmarkdown v1.10. The app works as it should except for the final step during which I use render() to knit the .Rmd to a .pdf.

pdflatex is installed and accessible in my container:

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

My 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 server log:

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

I have verified that the GA_report.knit.md is created successfully (along with all figures in the .Rmd file). In the container in an R session, I can run render() on the ...knit.md file and create the final beamer presentation .pdf without issue. It's just that the final step wherein the *.knit.md is converted to .pdf and is offered for download fails.

When I look in the dir that contains my .Rmd file, there is no .tex file, only the GA_report.knit.md and GA_report.utf8.md.

The header of my .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
---

The render() statement

render("report/GA_report.Rmd", 
       output_format = "all",
       output_file = file, 
       params = params, 
       envir = new.env(parent = globalenv()), 
       clean = FALSE, 
       quiet = FALSE)

My custom beamer theme is accessible in the container

root@de4bd1ee457a:/# kpsewhich beamerthemeSwCustom.sty
/opt/TinyTeX/texmf-dist/tex/latex/beamer/beamerthemeSwCustom.sty

What could be going on here? It seems like all signs should be pointing to yes when it comes to getting the file to completion, but I'm at a loss as to what could be the issue.

Upvotes: 1

Views: 288

Answers (1)

Steven
Steven

Reputation: 3292

I believe this is related to a max timeout error in Shiny Server. My docker container is running Shiny Server and, this issue on the Shiny Server github suggests that there is a hard-coded timeout in downloadHandler() in Shiny Server. As my .Rmd files are rather large, it takes much longer to convert to .pdf than the auto timeout. Because downloadHandler() never offered what I expected up for download, I would cancel the process and the final .pdf was never created.

Refactoring my app to include two buttons, one for generating the report and one for downloading the report, was my solution. This got around the hard-coded timeout for downloadedHandler() by allowing the knitting of the .Rmd to take place outside of downloadHandler().

Upvotes: 3

Related Questions