Skip to content

Instantly share code, notes, and snippets.

@MilesMcBain
Created June 27, 2022 23:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MilesMcBain/d2599f31e187ead226aa1b2355efbe15 to your computer and use it in GitHub Desktop.
Save MilesMcBain/d2599f31e187ead226aa1b2355efbe15 to your computer and use it in GitHub Desktop.
cloud_view()
cloud_view <- function(obj) {
withr::with_options(
list(viewer = function(url, ...) {
get_url_dir <- function(url) gsub("file://|/index.html", "", url)
server <- servr::httd(
dir = get_url_dir(url),
verbose = TRUE,
browser = FALSE
)
.vsc.browser(server$url, ...)
}),
print(obj)
)
}
@MilesMcBain
Copy link
Author

MilesMcBain commented Jun 27, 2022

If you have this in your .Rprofile anytime you want to view the output of a {htmlwidget} in VSCode when working over ssh, you pipe it to cloud_view(). Not ideal, but better than having nothing. If you use this a lot you'll accumulate servr instances, which you'll probably want to clean up, servr has a number of functions for handling this.

@MilesMcBain
Copy link
Author

I assume there was a reason I didn't just set the viewer option to this in my remote .Rprofile, I suspect it's to do with wanting to avoid messing with other things that do work fine, like Shiny apps, but I can't remember.

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