Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
naelske_cronos
Helper III
Helper III

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
v-rzhou-msft
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 @v-rzhou-msft 

 

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.