Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try render and check for pdflatex #108

Merged
merged 15 commits into from
Jul 8, 2022
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Suggests:
lattice,
png,
rtables (>= 0.5.1),
testthat
testthat,
tinytex
VignetteBuilder:
knitr
RdMacros:
Expand Down
41 changes: 34 additions & 7 deletions R/DownloadModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ download_report_button_ui <- function(id) {
#' @param reporter [`Reporter`] instance.
#' @param rmd_output `character` vector with `rmarkdown` output types,
#' by default all possible `c("pdf_document", "html_document", "powerpoint_presentation", "word_document")`.
#' `pdflatex` has to be installed to use the `"pdf_document"` output.
#' @param rmd_yaml_args `named list` vector with `Rmd` `yaml` header fields and their default values.
#' Default `list(author = "NEST", title = "Report", date = Sys.Date(), output = "html_document")`.
#' Please update only values at this moment.
Expand Down Expand Up @@ -144,24 +145,50 @@ report_render_and_compress <- function(reporter, input_list, file = tempdir()) {
checkmate::assert_list(input_list, names = "named")
checkmate::assert_string(file)

yaml_header <- as_yaml_auto(input_list)
if (identical("pdf_document", input_list$output) &&
inherits(try(system2("pdflatex --version", stdout = TRUE), silent = TRUE), "try-error")) {
Polkas marked this conversation as resolved.
Show resolved Hide resolved
shiny::showNotification(
ui = "pdflatex is not available so the pdf_document could not be rendered. Please use other output type.",
action = "Please contact app developer",
type = "error"
)
stop("pdflatex is not available so the pdf_document could not be rendered.")
}

yaml_header <- as_yaml_auto(input_list)
renderer <- Renderer$new()
renderer$render(reporter$get_blocks(), yaml_header)
temp_zip_file <- tempfile(fileext = ".zip")

tryCatch(
renderer$render(reporter$get_blocks(), yaml_header),
warning = function(cond) {
shiny::showNotification(
ui = "Render document warning!",
action = "Please contact app developer",
type = "warning"
)
},
error = function(cond) {
shiny::showNotification(
ui = "Render document error!",
action = "Please contact app developer",
type = "error"
)
}
)

temp_zip_file <- tempfile(fileext = ".zip")
tryCatch(
expr = zip::zipr(temp_zip_file, renderer$get_output_dir()),
warning = function(cond) {
shiny::showNotification(
ui = sprintf("Zipping folder warning!"),
ui = "Zipping folder warning!",
action = "Please contact app developer",
type = "warning"
)
},
error = function(cond) {
shiny::showNotification(
ui = sprintf("Zipping folder error!"),
ui = "Zipping folder error!",
action = "Please contact app developer",
type = "error"
)
Expand All @@ -172,14 +199,14 @@ report_render_and_compress <- function(reporter, input_list, file = tempdir()) {
expr = file.copy(temp_zip_file, file),
warning = function(cond) {
shiny::showNotification(
ui = sprintf("Copying file warning!"),
ui = "Copying file warning!",
action = "Please contact app developer",
type = "warning"
)
},
error = function(cond) {
shiny::showNotification(
ui = sprintf("Copying file error!"),
ui = "Copying file error!",
action = "Please contact app developer",
type = "error"
)
Expand Down
4 changes: 4 additions & 0 deletions R/Previewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ reporter_previewer_ui <- function(id, rmd_output = c(
author = "NEST", title = "Report",
date = as.character(Sys.Date()), output = "html_document"
)) {
checkmate::assert_list(rmd_yaml_args)

ns <- shiny::NS(id)
encoding <- shiny::tagList(
shiny::tags$h3("Download the Report"),
Expand Down Expand Up @@ -76,6 +78,8 @@ reporter_previewer_srv <- function(id, reporter, rmd_yaml_args = list(
date = as.character(Sys.Date()), output = "html_document"
)) {
checkmate::assert_class(reporter, "Reporter")
checkmate::assert_list(rmd_yaml_args)

shiny::moduleServer(
id,
function(input, output, session) {
Expand Down
3 changes: 2 additions & 1 deletion man/download_report_button_srv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.