Skip to content

Instantly share code, notes, and snippets.

@tim-salabim
Created May 1, 2021 08:46
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 tim-salabim/bbe1c588d0444f1c2cc90d8a8dfa6690 to your computer and use it in GitHub Desktop.
Save tim-salabim/bbe1c588d0444f1c2cc90d8a8dfa6690 to your computer and use it in GitHub Desktop.
Create custom CSS to use in popupTable
library(leaflet)
library(leafpop)
## using a custom css to style the table
className = "my-popup"
css = list(
"background" = "#ff00ff"
)
css = list(css)
names(css) = sprintf("table.%s", className)
evenodd = list("#ffff00", "#00ffff")
names(evenodd) = rep("background", 2)
evenodd = lapply(evenodd, function(i) {
list("background" = i)
})
names(evenodd) = c(
sprintf("table.%s tr:nth-child(even)", className)
, sprintf("table.%s tr:nth-child(odd)", className)
)
lst = append(css, evenodd)
jnk = Map(function(...) do.call(htmltools::css, ...), lst)
dir = tempfile()
dir.create(dir)
fl = file.path(dir, "myCSS.css")
cat(
sprintf(
"%s{ \n %s\n}\n\n"
, names(jnk)
, jnk
)
, sep = ""
, file = fl
)
mymap = leaflet() %>%
addTiles() %>%
addCircleMarkers(data = breweries91,
popup = popupTable(breweries91, className = className))
addMyCSSDependency = function() {
list(
htmltools::htmlDependency(
name = "mycss"
, version = "0.0.1"
, src = dir
, stylesheet = basename(fl)
)
)
}
mymap$dependencies = c(
mymap$dependencies
, addMyCSSDependency()
)
mymap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment