Created
February 26, 2023 19:37
-
-
Save jthomasmock/85d9ef681494bed1f1295a4b16d43476 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gt_render_reprex <- function(gt_object, imgur = FALSE) { | |
# create temp file | |
img_out <- tempfile(fileext = ".png") | |
# save image to temp | |
save_obj <- gt::gtsave(gt_object, img_out) %>% | |
utils::capture.output(type = "message") %>% | |
invisible() | |
on.exit(unlink(img_out)) | |
# if imgur, print a markdown link | |
if (imgur) { | |
msg_out <- knitr::imgur_upload(img_out) | |
cat(paste0("![](", msg_out[[1]], ")")) | |
knitr::include_graphics(as.character(msg_out[[1]])) | |
} else { | |
# just include the image | |
knitr::include_graphics(img_out) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment