Created
May 1, 2021 08:46
-
-
Save tim-salabim/bbe1c588d0444f1c2cc90d8a8dfa6690 to your computer and use it in GitHub Desktop.
Create custom CSS to use in popupTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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