diff --git a/DESCRIPTION b/DESCRIPTION index 591787057..151c87fce 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -84,4 +84,4 @@ Encoding: UTF-8 Language: en-US LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 diff --git a/R/toHTML.R b/R/toHTML.R index 04b4f4070..c22428b8e 100644 --- a/R/toHTML.R +++ b/R/toHTML.R @@ -77,8 +77,9 @@ toHTML.default <- function(x, ...) { #' @keywords internal .toHTML.gg <- function(x, ...) { on.exit(unlink(tmpfile)) + dims <- resolve_figure_dimensions(x, convert_to_inches = TRUE, dpi = 100) tmpfile <- tempfile(fileext = ".png") - ggplot2::ggsave(tmpfile, plot = x, width = 5, height = 4, dpi = 100) + ggplot2::ggsave(tmpfile, plot = x, width = dims$width, height = dims$height, dpi = 100) shiny::tags$img(src = knitr::image_uri(tmpfile)) } @@ -86,8 +87,9 @@ toHTML.default <- function(x, ...) { #' @keywords internal .toHTML.grob <- function(x, ...) { on.exit(unlink(tmpfile)) + dims <- resolve_figure_dimensions(x) tmpfile <- tempfile(fileext = ".png") - grDevices::png(filename = tmpfile) + grDevices::png(filename = tmpfile, width = dims$width, height = dims$height) grid::grid.newpage() grid::grid.draw(x) grDevices::dev.off() diff --git a/man/ReportCard.Rd b/man/ReportCard.Rd index f306892ae..4b21c311a 100644 --- a/man/ReportCard.Rd +++ b/man/ReportCard.Rd @@ -12,14 +12,14 @@ For more information about the various blocks, refer to the vignette: \code{vignette("teal-reporter-blocks-overview", "teal.reporter")}. } \examples{ -\dontshow{if (require("ggplot2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggplot2")) withAutoprint(\{ # examplesIf} library(ggplot2) card <- ReportCard$new()$append_plot( ggplot(iris, aes(x = Petal.Length)) + geom_histogram() ) \dontshow{\}) # examplesIf} -\dontshow{if (require("ggplot2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggplot2")) withAutoprint(\{ # examplesIf} library(ggplot2) card <- ReportCard$new()$append_text("Some text")$append_plot( @@ -29,7 +29,7 @@ card <- ReportCard$new()$append_text("Some text")$append_plot( card$get_content() card$get_metadata() \dontshow{\}) # examplesIf} -\dontshow{if (require("ggplot2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggplot2")) withAutoprint(\{ # examplesIf} library(ggplot2) card <- ReportCard$new()$append_text("Some text")$append_plot( @@ -40,7 +40,7 @@ card$get_content() card$to_list(tempdir()) \dontshow{\}) # examplesIf} -\dontshow{if (require("ggplot2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggplot2")) withAutoprint(\{ # examplesIf} library(ggplot2) card <- ReportCard$new()$append_text("Some text")$append_plot( diff --git a/man/Reporter.Rd b/man/Reporter.Rd index 1af179bde..04e55f160 100644 --- a/man/Reporter.Rd +++ b/man/Reporter.Rd @@ -16,7 +16,7 @@ if Report has an id when converting to JSON then It will be compared to the curr if Report has an id when converting to JSON then It will be compared to the currently available one. } \examples{ -\dontshow{if (require("ggplot2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggplot2")) withAutoprint(\{ # examplesIf} library(ggplot2) card1 <- teal_card("## Header 2 text", "A paragraph of default text") @@ -29,7 +29,7 @@ metadata(card2, "title") <- "Card2" reporter <- Reporter$new() reporter$append_cards(list(card1, card2)) \dontshow{\}) # examplesIf} -\dontshow{if (require("ggplot2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggplot2")) withAutoprint(\{ # examplesIf} library(ggplot2) library(rtables) @@ -53,7 +53,7 @@ names(reporter$get_cards()) reporter$reorder_cards(c("Card2", "Card1")) names(reporter$get_cards()) \dontshow{\}) # examplesIf} -\dontshow{if (require("ggplot2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggplot2")) withAutoprint(\{ # examplesIf} library(ggplot2) library(rtables) @@ -77,7 +77,7 @@ metadata(reporter$get_cards()[[1]], "title") reporter$replace_card(card2, names(reporter$get_cards())[[1]]) metadata(reporter$get_cards()[[1]], "title") \dontshow{\}) # examplesIf} -\dontshow{if (require("ggplot2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggplot2")) withAutoprint(\{ # examplesIf} library(ggplot2) library(rtables) @@ -96,7 +96,7 @@ reporter <- Reporter$new() reporter$append_cards(list(card1, card2)) reporter$get_cards() \dontshow{\}) # examplesIf} -\dontshow{if (require("ggplot2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggplot2")) withAutoprint(\{ # examplesIf} library(ggplot2) library(rtables)