Plotting libraries that support on_click events

Summary

I have a pandas dataframe, it has a few attributes such as name, salary, domain and coordinates. I need a plotting library that can plot these points on a scatter plot, where the .points will display the information on hover and will also perform certain actions if we click that point.

I have used plotly, but the on_click functionality is not implemented on Streamlit. There is a separate library called streamlit plotly events, but it seems its outdated because it produces a black and white plot. I am also free to use any other library if it fulfills my conditions

Additional information

There are some relevant codes I think which would help

Code snippet:

# sample pandas dataframe with one row:
dict1 = {'name': ['John'],
         'company': ['GreenStone'],
         'salary': [1000],
          x:[2.891],
          y:[3.442]}
df = pd.DataFrame(dict1)

#i am using plotly, but I can use other libraries too

import plotly.express as px

fig =px.scatter(df, x='x', y='y', size = 'salary',
                            hover_data= hover_dict)

def open_text(trace, points, selector):
    #do something
fig.data[0].on_click(open_text)

Expected behavior:

open_text function executes

Actual behavior:

nothing happens

Hi @Ayanjit_Chatterjee

Altair is another great plotting library that you can try out. Here’s a gallery page showing interactive features that you can implement on your plot:

https://altair-viz.github.io/gallery/index.html#interactive-charts

Hope this helps!

Does it support on click events? To my knowledge it doesn’t.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.