Popup titles other than LayerID?
beansrowning opened this issue · comments
One feature that I think is missing (or maybe it's not and I just haven't found it documented), is a way to give each popup a unique title beyond the layer name.
In my use case, I might have a choropleth with bar charts and I would like the popup to show the bar chart data for each region along with the name of the region as the title, for example:
Spain
x: 1234
y: 6478
and
France
x: 73907
y: 90682
I got around this with a hacky function I wrote in R and passed to the html parameter of popupArgs()
which more or less accomplishes what setPopup()
does with the addition of allowing a character vector of titles for each set of values:
popup_gen <- function(title, keys, values) {
stopifnot(length(title) == dim(values)[1L])
out <- vector("character", length = dim(values)[1L])
for (i in seq_along(out)) {
out[i] <- paste(
"<div class='popup'>",
sprintf("<h2>%s</h2>", title[i]),
"<table><tbody>",
paste(sprintf(
"<tr><td class='key'>%s</td><td class='value'>%i</td></tr>",
keys, values[i, keys]), collapse = ""),
"</tbody></table>",
"</div>",
sep = ""
)
}
return(out)
}
I'm not sure if this is a feature others would like, but it seems like it would be easy to implement in JS (or R as I have done). Happy to help out with a PR if you'd like.
I think it's what I need :) I guess I'm pretty close, but I get a message error when trying your method.
"Error in popupArgs$html[correctOrder] :
object of type 'closure' is not subsettable"
I try to add a tittle to the popups using addMinicharts with charts of type "pie"...
I'll keep on going
See yu