I have a dash app that I’m working on with multiple graphs. Each graph is a scatter plot and has a color by of ‘Included’ or ‘Excluded’.
We are showing the excluded points for visual purposes of outliers, but we don’t want to actually use them in any calculations.
A user can lasso select a group of points and recalculate a new average. However if they accidentally select an ‘Excluded’ point, we don’t want that to be included in the average.
Does anyone have any idea on how to do this? In the lasso select data it doesn’t show the color by classification and I’ve tried matching it up with the figure data to no avail. The way my app is set up doesn’t have direct access to the dataframe but I guess I could change that if I needed to.
Any thoughts?
Here is some sample code if this helps.
data = pd.DataFrame({'x': [1, 2, 3, 4, 5],
'y': [5, 4, 3, 2, 1],
'color': ['Included', 'Excluded', 'Included', 'Included', 'Excluded']})
fig_warm = px.scatter(
data ,
x='x',
y='y',
color='color',
color_discrete_map={
'Excluded': 'lightgrey',
'Included': '#FF7F0F'
}
)
@app.callback(
Output('avg-start-up-duration', 'rowData'),
Input('warm-plot', 'selectedData'),
Input('warm-plot', 'figure')
)
def update_avg_table_from_lasso_select(warm_selected_data, warm_plot):
if not warm_selected_data:
return dash.no_update
if warm_selected_data:
selected_indices = [point['pointIndex'] for point in warm_selected_data['points']]
current_data = warm_plot['data'][0]
selected_x = [current_data['x'][i] for i in selected_indices]
selected_y = [current_data['y'][i] for i in selected_indices]
It’ll eventually update a Ag Grid, I just haven’t incorporated that yet since I can’t even get the data I want right now.