Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popup titles other than LayerID? #24

Open
beansrowning opened this issue Jun 23, 2018 · 1 comment
Open

Popup titles other than LayerID? #24

beansrowning opened this issue Jun 23, 2018 · 1 comment

Comments

@beansrowning
Copy link

beansrowning commented Jun 23, 2018

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.

@clap-hands-in-the-r
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants