plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
16.88k stars 1.85k forks source link

Adding layers makes tooltips disappear #7071

Open Nova-Scotia opened 1 month ago

Nova-Scotia commented 1 month ago

Hi there,

I'm experiencing the same issue as @borenstein, referenced here: Adding layer makes tool tips disappear. Someone asked @borenstein to post the issue here but I didn't see a record of it. Here's a shorter reproducible example and summary; please note their solution (comparing data on hover) doesn't work in my use case (not shown here).

I want to create a plot where users can hover over a map and a tooltip for a single layer appears, for example, showing the names of US counties, with state boundaries overlaid on the map. If your mouse is "far" from a state boundary, the tooltip appears. However, if you are "close" (e.g., southeastern edge of map), the tooltip does not appear.

I've tried identifying the traces that contain parts of my plot that I don't want to show tooltips for - as in these stack overflow posts:

But, it doesn't work.

library(plotly)
library(tidyverse)

### New England: *sometimes* shows tool tips
new_england <- c("maine", "new hampshire", "vermont", "massachusetts", "connecticut", "rhode island")

b <- ggplot2::map_data("state") %>%
  filter(region %in% new_england)

a <- data.frame(group = seq(3085), val = rnorm(3085)) %>%
  left_join(ggplot2::map_data("county"), by = "group") %>%
  filter(region %in% new_england)

p <- ggplot(a, aes(long, lat, group = group)) +
  geom_polygon(aes(fill = val, text = subregion)) +
  geom_path(data = b, color = "black")

ggplotly(p, tooltip="text")

image

image

Tagging @MountainCedar so they know I've filed an issue about this.

borenstein commented 1 month ago

Wow @Nova-Scotia, this is a blast from the past! I actually have not really done much data visualization the last several years.