All examples By author By category About

timelyportfolio

R leaflet popups with sparkline htmlwidget

See DT issue

library(leaflet)

m = leaflet() %>% addTiles()

# popup
rand_lng = function(n = 10) rnorm(n, -93.65, .01)
rand_lat = function(n = 10) rnorm(n, 42.0285, .01)

# use automatic bounds derived from lng/lat data
m = m %>% clearBounds()

# popup
m %>% addPopups(
  rand_lng(),
  rand_lat(),
  lapply(1:10, function(x){
    as.character(sparkline(runif(10)))
  })
) %>%
  onRender(
"
function(el,x) {HTMLWidgets.staticRender()}
"
  ) %>%
  add_deps("sparkline", "sparkline") %>%
  browsable()