I have a chart where when a user clicks on an event, it brings up more data for that selected event, however, anytime a user clicks on a point, the chart resets and because I have over 90 data points, I would like the chart to stay where the user scrolled/selected the data point instead of resetting back down to the bottom.
Here is the code I’m using:
#create chart
event_chart = px.scatter(df, x="total_mass_source", y="commonName")
event_chart.update_layout(
xaxis_title="Total Mass",
yaxis_title="Event",
yaxis=dict(
tickmode='array',
title='Event', # Set your y-axis title here
),
margin=dict(l=150), # Adjust the left margin value to create more space for the y-axis labels
)
event_chart.update_xaxes(range=[0,200],
title_font = {"size": 20},
title_standoff = 20,
)
event_chart.update_yaxes(range=[0,20],
title_font = {"size": 20},
title_standoff = 50,
)
#get user input
select_event = plotly_events(event_chart, click_event=True)
selected_gwc_event = [point['y'] for point in select_event]
# Display the selected points
st.write("Selected Event:", selected_gwc_event)
Here is a live example:
Dashboard
You can scroll up and click on a data point and you’ll notice how it will reset after the click event loads.