cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
naelske_cronos
Helper I
Helper I

Custom Visual R - leaflet with highcharter tooltip

Hello,

 

I'm trying to add a chart as a tooltip when clicking on my data point in a map.

For this I'm using the leaflet package to create a map and the data point on a specific location and the chart as a tooltip comes from the highcharter package. I'm basically trying to get the same result as discussed in this link on StackOverflow: https://stackoverflow.com/questions/59173708/r-leaflet-highcharter-tooltip

 

This is the piece of code that is used in my custom visual based in R, so with RHTML ->

 

 

 

source('./r_files/flatten_HTML.r')

############### Library Declarations ###############
libraryRequireInstall("leaflet");
libraryRequireInstall("sf");
libraryRequireInstall("htmlwidgets");
libraryRequireInstall("dplyr");
libraryRequireInstall("stringr");
libraryRequireInstall("htmltools");
libraryRequireInstall("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_Map <- leaflet()
Leaflet_Map <- addProviderTiles(Leaflet_Map, providers$CartoDB)
Leaflet_Map <- addCircleMarkers(Leaflet_Map, 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))


Leaflet_Map <-  onRender(Leaflet_Map,
    "
function(el,x) {
  this.on('popupopen', function() {HTMLWidgets.staticRender();})
}
") %>% add_deps("highchart", 'highcharter')  %>% browsable()
############# Create and save widget ###############
internalSaveWidget(Leaflet_Map, 'out.html')

 

 

 

 

The problem is that the piece of code 'add_deps("highchart", 'highcharter')' gives me the error. If I remove it, I'm almost getting the right result which is an empty box. 

CVR.PNG

But when I use the full code with the adding of 'add_deps("highchart", 'highcharter')', I get this error:
Error.PNG

 

My first thought was to change something in the function internalSaveWidget which resides in the 'flatten_HTML.r' file.

 

Can somebody help me with this problem please?

2 REPLIES 2
RicoZhou
Community Support
Community Support

Hi @naelske_cronos ,

 

Please refer to this blog to check whether your highchart option is correct.

For reference: What is highcharter?

Here is a similar post like yours about how to add tooltips in Power BI custom R visual.

For reference: Change R visual to Custom visual with Tooltip

I hope they could help you solve your problem.

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello @RicoZhou 

 

I don't have enough with this information. I thought having more information about the error in the code but no problem. I'll not accept this as an answer to my solution but thanks for your reply.


I used another method to show a tooltip with the R custom visual and this is saving a plot with the ggplot package to a SVG file. This works perfectly!

 

 

Kind regards

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.