From 9e35e8c947e1a2a76ff92a3cebfb6b46fea3207e Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Fri, 16 Mar 2018 23:01:06 -0500 Subject: [PATCH] Allow user code to pass width/height/pixelratio --- R/render-plot.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/R/render-plot.R b/R/render-plot.R index 1960fe3f7..d44c9321c 100644 --- a/R/render-plot.R +++ b/R/render-plot.R @@ -1065,7 +1065,7 @@ find_panel_ranges <- function(g, pixelratio, res) { #' #' @export plotCache <- function(invalidationExpr, plotFunc, - width, height, res = 72, + width = 400, height = 400, res = 72, cacheDir = NULL, invalidation.env = parent.frame(), invalidation.quoted = FALSE, @@ -1122,13 +1122,18 @@ plotCache <- function(invalidationExpr, plotFunc, } ) - function(...) { + function(..., .width = width, .height = height, .pixelratio = getDefaultReactiveDomain()$clientData$pixelratio) { + args <- list(...) - key <- paste0(digest::digest(args), ".png") + # TODO: What if the args include weird objects like environments or reactive expressions? + key <- paste0(digest::digest(c(args, width = .width, height = .height, res = res, pixelratio = .pixelratio)), ".png") filePath <- file.path(cacheDir, key) if (!file.exists(filePath)) { plotPNG( - filename = filePath, width = width, height = height, res = res, + filename = filePath, + width = .width * .pixelratio, + height = .height * .pixelratio, + res = res * .pixelratio, function() { do.call("plotFunc", args) }