R - 传单 - highcharter 工具提示(标签)

R - leaflet - highcharter tooltip (label)

阅读此 的解决方案后。我尝试调整标签的解决方案(不是弹出窗口)。

当我尝试弹出窗口的解决方案时。完美运行

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()

但是当我尝试标签时。我无法达到相同的结果。有人可以解释一下为什么吗?

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()

抱歉,答案很简单,函数应该是:

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()

它是 tooltipopen 而不是 mouseOver 我希望它会对某人有所帮助:)