Skip to content

Instantly share code, notes, and snippets.

@ColinFay
Created March 24, 2021 08:04
Show Gist options
  • Save ColinFay/2d2a489947a3708c288ecdb546c9df1f to your computer and use it in GitHub Desktop.
Save ColinFay/2d2a489947a3708c288ecdb546c9df1f to your computer and use it in GitHub Desktop.
html_template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<style>body{background-color:white;}</style>
</head>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
</head>
<body>
<style>
#mapid { height: 180px; }
</style>
<div id="mapid"></div>
<script>
var mymap = L.map('mapid').setView([51.505, -0.09], 13);
var polygon = L.polygon([[51.509,-0.08],[51.503,-0.06],[51.51,-0.047]]).addTo(mymap);
</script>
</body>
</html>
</html>
library(magrittr)
list(
c(51.509, -0.08),
c(51.503, -0.06),
c(51.51, -0.047)
) %>%
jsonlite::toJSON() %>%
htmltools::htmlTemplate(
"template.html",
polygons = .
) %>%
htmltools::save_html("filled_template.html")
browseURL("filled_template.html")
<html>
<head>
<title>Title</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
</head>
<body>
<style>
#mapid { height: 180px; }
</style>
<div id="mapid"></div>
<script>
var mymap = L.map('mapid').setView([51.505, -0.09], 13);
var polygon = L.polygon({{polygons}}).addTo(mymap);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment