Skip to content

Instantly share code, notes, and snippets.

@kar9222
Last active April 10, 2021 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kar9222/be90067e4256aaea124eb0f30db63d99 to your computer and use it in GitHub Desktop.
Save kar9222/be90067e4256aaea124eb0f30db63d99 to your computer and use it in GitHub Desktop.
SVG graphic device in external browser

In .Rprofile

# Install ----------------------------------------

install.packages('httpgd')
# or latest development
devtools::install_github('nx10/httpgd')

# Minimal ----------------------------------------

if ('httpgd' %in% .packages(all.available = TRUE)) {
  options(
    # Disable VSCode's WebView to use external web browser
    vsc.plot = FALSE, vsc.browser = FALSE,

    device = function(...) {
      httpgd::hgd(silent = TRUE)
      httpgd::hgd_browse()
    }
  )
}

# More customization -----------------------------

if ('httpgd' %in% .packages(all.available = TRUE)) {
  options(
    # Disable VSCode's WebView to use external web browser
    vsc.plot = FALSE, vsc.browser = FALSE,

    device = function(...) {
      httpgd::hgd(silent = TRUE)
      # Customize browser
      httpgd::hgd_browse(
        # Disable plot history sidebar on startup. Default is TRUE.
        history = FALSE,
        browser = function(url) {
          # Customize my_browser. Use browser app mode to hide url bar.
          system2('my_browser', paste0('--app=', url))
          # e.g. Chrome on Linux
          # system2('google-chrome-stable', paste0('--app=', url))
          # e.g. Chrome on Windows
          # system2('chrome.exe', paste0('--app=', url))
      })
    }
  )
}

# Plot -------------------------------------------

plot(iris)
library(ggplot2)
ggplot(mtcars) + geom_point(aes(mpg, disp, col = cyl))
ggplot(iris) + geom_histogram(aes(Sepal.Length))

httpgd2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment