R-传单-高图提示(标签)

问题描述 投票:0回答:1

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

[当我尝试弹出式解决方案时。效果很好

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

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

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

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("highchar**strong text**t", 'highcharter') %>%
  browsable()

enter image description here

r highcharts leaflet r-leaflet r-highcharter
1个回答
0
投票

对不起,答案很简单,功能应该是:

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("highchar**strong text**t", 'highcharter') %>%
  browsable()

tooltipopen而不是mouseOver我希望它可以帮助某人:)

© www.soinside.com 2019 - 2024. All rights reserved.