R/helpers.R

Defines functions makePlotURI

Documented in makePlotURI

#' Helper function to make the ggplot output from LIME suitable for leaflet.
#'
makePlotURI <- function(expr, width, height, ...) {
    pngFile <- shiny::plotPNG(function() { expr },
                              width = width,
                              height = height, ...)
    on.exit(unlink(pngFile))

    base64 <- httpuv::rawToBase64(readBin(pngFile, raw(1), file.size(pngFile)))
    paste0("data:image/png;base64,", base64)
}
boyanangelov/sdmexplain documentation built on Nov. 26, 2019, 2:56 a.m.