Skip to content

Instantly share code, notes, and snippets.

@jthomasmock
Created February 26, 2023 19:37
Show Gist options
  • Save jthomasmock/85d9ef681494bed1f1295a4b16d43476 to your computer and use it in GitHub Desktop.
Save jthomasmock/85d9ef681494bed1f1295a4b16d43476 to your computer and use it in GitHub Desktop.
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