Black Lives Matter. Please consider donating to Black Girls Code today.

Callback function on Sankey diagram

Hi Plotly community!

I have just started with Plotly for python and I am already stuck :confused:
When I use a callback function (e.g. on_click) how can I distinguish between a node and a edge object?

I am using the following approach:

def update_color(trace, points, state):
# Compute new color array
new_color = np.array(fig.data[0].node.color)
new_color[points.point_inds[0]] = “red”
with fig.batch_update():
fig.data[0].node.color = new_color

fig.data[0].on_click(update_color)

The problem with this approach is that the id of links and nodes overlap. Therefore, when I click on any link between nodes the id of the link is used to choose and color the node with that id. Clearly, if there are more links than nodes, than such click can also lead to an out-of-index error.
I would really appreciate your help here.