Skip to content

Commit 6d19e5a

Browse files
committed
try harder to find bitmap device and throw warning if none is found
1 parent 549fba9 commit 6d19e5a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

R/ggplotly.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,21 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
119119
# if height/width is not specified, estimate it from the current device
120120
deviceWidth <- width %||% unitConvert(grid::unit(1, "npc"), "pixels", "width")
121121
deviceHeight <- height %||% unitConvert(grid::unit(1, "npc"), "pixels", "height")
122-
tmpPlotFile <- tempfile(fileext = ".png")
123-
grDevices::png(tmpPlotFile, width = deviceWidth, height = deviceHeight)
122+
# try to find a bitmap device (measured in pixels),
123+
# if none available, use default device and throw warning
124+
dev_fun <- if (capabilities("png")) {
125+
grDevices::png
126+
} else if (capabilities("jpeg")) {
127+
grDevices::jpeg
128+
} else {
129+
warning(
130+
"Couldn't find a bitmap device (e.g. png or jpeg).",
131+
"To ensure sizes are converted correctly please",
132+
"compile R to use a bitmap device", call. = FALSE
133+
)
134+
grDevices::dev.new
135+
}
136+
dev_fun(tmpPlotFile, width = deviceWidth, height = deviceHeight)
124137

125138

126139
plot <- ggfun("plot_clone")(p)

0 commit comments

Comments
 (0)