2

After reading the solution of this question. I have tried to adapt the solution for the label (not the popup).

When I try the solution for the popup. It works perfectly

library(leaflet)
library(tidyverse)
library(htmlwidgets)
library(htmltools)
library(sparkline)
library(highcharter)

as.character.htmlwidget <- function(x, ...) {
  htmltools::HTML(
    htmltools:::as.character.shiny.tag.list(
      htmlwidgets:::as.tags.htmlwidget(
        x
      ),
      ...
    )
  )
}


add_deps <- function(dtbl, name, pkg = name) {
  tagList(
    dtbl,
    htmlwidgets::getDependency(name, pkg)
  )
}

leaflet() %>% 
  addTiles() %>% 
  addCircleMarkers(lat = 45.4, lng = 14.9,
                   popup = list(paste(as.character(
                     hchart(data.frame(x = 1:10, y = 1:10), type = "line", hcaes(x = x, y = y)) %>% 
                     hc_size(width = 300, height = 200)
                   ))),
                   popupOptions = popupOptions(minWidth = 300, maxHeight = 200)) %>%
  onRender(
    "
function(el,x) {
  this.on('popupopen', function() {HTMLWidgets.staticRender();})
}
") %>%
  add_deps("highchart", 'highcharter') %>%
  browsable()

enter image description here

But When I try for the label. I am not able to reach the same result. Somebody can explain me why please?

leaflet() %>% 
  addTiles() %>% 
  addCircleMarkers(lat = 45.4, lng = 14.9,
                   label =  lapply(paste(as.character(
                     hchart(data.frame(x = 1:10, y = 1:10), type = "line", hcaes(x = x, y = y)) %>% 
                     hc_size(width = 300, height = 200))), htmltools::HTML),
                   labelOptions = popupOptions(minWidth = 300, maxHeight = 200) 
                   )  %>%
  onRender(
    "
function(el,x) {
  this.on('mouseOver', function() {HTMLWidgets.staticRender();})
}
") %>%
  add_deps("highchart", 'highcharter') %>%
  browsable()

enter image description here

Woza
  • 205
  • 3
  • 9

1 Answers1

3

Sorry, the answer was easy, the function should be :

leaflet() %>% 
  addTiles() %>% 
  addCircleMarkers(lat = 45.4, lng = 14.9,
                   label =  lapply(paste(as.character(
                     hchart(data.frame(x = 1:10, y = 1:10), type = "line", hcaes(x = x, y = y)) %>% 
                     hc_size(width = 300, height = 200))), htmltools::HTML),
                   labelOptions = popupOptions(minWidth = 300, maxHeight = 200) 
                   )  %>%
  onRender(
    "
function(el,x) {
  this.on('tooltipopen', function() {HTMLWidgets.staticRender();})
}
") %>%
  add_deps("highchart", 'highcharter') %>%
  browsable()

It's tooltipopen not mouseOver I hope it will help someone :)

Woza
  • 205
  • 3
  • 9