Draw line between scatter plot points when clicked

I’m new to plotly so please excuse my naivety. I’ve tried searching all over these forums and other locations, but can’t seem to find any relevant posts that cover this topic.

I’ve generated a scatter plot that displays on mouse hover:

  1. the point ID
  2. the nearest neighbor to that point
  3. the distance to the nearest neighbor

What I’d like to do:
Click on a point (or also on hover) and draw a line to its nearest neighbor.

I’ve reduced the dimensionality from 18d to 2d to better visualize my distributions and as a result, the nearest point in 2d isn’t representative of what exists in 18d. I’d like to be able to draw a line to that point, grabbing the coordinates to the nearest neighbor from my pandas dataframe.

Has anyone covered this before or could steer me in the right direction? I’ll be eternally grateful :slight_smile: