Skip to content

Instantly share code, notes, and snippets.

@behrica
Last active August 15, 2021 09:51
Show Gist options
  • Save behrica/1c269a661bd674d223b4c6ce58b5045a to your computer and use it in GitHub Desktop.
Save behrica/1c269a661bd674d223b4c6ce58b5045a to your computer and use it in GitHub Desktop.
Proof of concept for htmlwidget integration in org mode
renderDeps <- function(widget,dir=".",libdir="lib") {
  rendered <- htmltools::renderTags(widget)

  deps <- lapply(rendered1$dependencies, function(dep) {
    dep <- htmltools::copyDependencyToDir(dep, libdir, FALSE)
    dep <- htmltools::makeDependencyRelative(dep, dir, FALSE)
    dep
  })
  htmltools::renderDependencies(deps, c("href", "file"))
  
}

renderWidgetToFile <- function(widget,filename) {
   widget$sizingPolicy = htmlwidgets::sizingPolicy(browser.fill = FALSE)
   rendered <- htmltools::renderTags(widget)
   writeLines(rendered$html,filename)
}

library(tmap)
library(htmlwidgets)

data(World, rivers, metro)
m1=qtm(World, fill = "economy", format = "World", style = "col_blind")

lf1=tmap_leaflet(m1)



renderDeps(lf1)

map 1

renderWidgetToFile(lf1,"map1.html")

map 2

m2=qtm(World)
lf2=tmap_leaflet(m2)

renderWidgetToFile(lf2,"map2.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment