- See {httpgd} -- Asynchronous http server graphics device for R
- See Using httpgd in VSCode: A web-based SVG graphics device
- VSCode's integration: See WIP/Proof of concept: Integrate httpgd #614
- Personally, I prefer using external browser or graphic device for positioning my plot in the center, more flexible layout, etc.
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))