Plotly chart selection for heatmap with streamlit 1.35.0

Hi,

First of all, thanks for the new update !

I was really happy to see the plotly events being natively incorporated in streamlit, cool feature ! However, it would seem it doesn’t yet work with all types of plotly graph. This may be intended but I wasn’t able to confirm this information.

I’m running the app locally using python 3.11.9 and streamlit 1.35.0.

When I try to use the new on_select parameter of st.plotly_chart with a go.Heatmap it doesn’t seem to work whereas the exact same code using go.Scatter works fine as you can see with the following sample code :

import streamlit as st
import plotly.graph_objs as go

fig1 = go.Figure(data=go.Heatmap(x=[1, 2, 3, 4], y=[10, 11, 12, 13], z=[10, 11, 12, 13]))

event1 = st.plotly_chart(fig1, key="1", on_select="rerun")

st.write(event1.selection)

fig2 = go.Figure(data=go.Scatter(x=[1, 2, 3, 4], y=[10, 11, 12, 13], mode='markers'))

event2 = st.plotly_chart(fig2, key="2", on_select="rerun")

st.write(event2.selection)

Clicking on the the heatmap doesn’t do anything whereas clicking the scatter plot works.

Having implemented a custom component for clicking on heatmaps, I know it works similarly for heatmaps and other graphs so i’m wondering why it doesn’t work the same as go.Scatter.

Do you have any information related to this ?

1 Like

Yes it is a pain.
Try creating a scatter plot on top of this figure that just mimics the coordinates of the heatmap using fig.add_trace
Then reduce the size of the markers and it will work.

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