Scatterplot Box/Lasso Selection Persistence

Hi all:

I have an application build on Plotly Dash that uses a Scatterplot to display a data points. We allow the user to both box and lasso select a given region. This selection triggers a query to the backend for information on the selected data points. Ideally, I want to be able to persist the box selection outline (or lasso selection outline) on the screen between queries. I’ve tried experimenting with a number of properties including ‘uirevision’ and ‘selectionrevision’, but I am unable to persist the selection outline between UI updates/queries to the backend.

Is this possible to do?

Thanks for any help!!!

Hello @userandrew,

Were you able to do this?
I am trying to do that now but can’t find a way to do it.

Hello @trinityimma,

Can you explain or give an MRE of what is happening?

If you are returning a figure to the one that you are altering, I don’t there is a way unless you can pass back the selected points to the selected points argument of the figure.

@jinnyzor
Yes, I have a scatter plot shown below.
I have a call back which is used to select the data points using either the lasso or box.

I have another callback which use the selected data to choose some other data to be exported for an analysis in other software.
All the data are being stored in dcc.Store as shown in the callback.

def selection_fn(selectedData, init_press, aq_tr, Noi, rock_comp, gas_prd,
                 gas_prd_eff, gas_inj_eff, water_prd_eff, water_inj_eff, interp_kind, root_method):
    lstwells = []
    if selectedData:
        lstwells = [i['text'] for i in selectedData['points']]

    store = {}
    store['lstwells'] = lstwells
    store['init_press'] = init_press
    store['aq_transm'] = aq_tr
    store['ooip'] = Noi
    store['rock_comp'] = rock_comp
    store['gas_prd'] = gas_prd
    store['gas_prd_eff'] = gas_prd_eff
    store['gas_inj_eff'] = gas_inj_eff
    store['water_prd_eff'] = water_prd_eff
    store['water_inj_eff'] = water_inj_eff
    store['root_method'] = root_method
    store['interp_kind'] = interp_kind

    return store

But when I refresh the tab, all other parameters in the store remains except for the selected Data from the graph.
I need to find a way to be able to save the selected data because the user may still wants to have access to that for further comparison and analysis. I want to start with persisting first.

So, I am guessing that this maybe because other data are persisted while the selectedData is not.

The end goal is that I want the user to be able to save the selected data and when it is further needed, it can be put back to the plot and selected by default. I hope I make sense.

Just a guess:

Maybe this is because at reselecting the tab, the callback gets triggered and selectedData is overwritten as there are no points selected at this moment. Do you use prevent_initial_call=True for this callback?

1 Like

@AIMPED just to understand more.

You mean I should check if there is selectedData and if there is not, I should prevent call to the callback?

Also, just like other components, is it not possible to just persist the selectedData? I did check the graph component but there is no persistence attribute though.

I didn’t use prevent_initial_call

Why do I need to prevent the initial call?

@trinityimma,

It’s hard to say what is exactly is happening without also seeing your callback. Preventing the initial call will keep the selectedData from clearing after the chart displays for the first time.

1 Like

I will rephrase the question for better understanding of all.

I want the selectedData to be persisted and stored at the store no matter how many times it is called.
Just the same way value of a checkbox or input component is persisted. This way, when the tab is refreshed it will still be in available in the storage.

Right now, when the tab refresh, all other values in the store remains as of the last time it was edited. But the selected data goes back to an empty list.

The callback function is reposted here:
The inputs are all those parameters of the function including the selectedData from the graph while the output is the data component of the dcc.Store

def selection_fn(selectedData, init_press, aq_tr, Noi, rock_comp, gas_prd,
                 gas_prd_eff, gas_inj_eff, water_prd_eff, water_inj_eff, interp_kind, root_method):
    lstwells = []
    if selectedData:
        lstwells = [i['text'] for i in selectedData['points']]

    store = {}
    store['lstwells'] = lstwells
    store['init_press'] = init_press
    store['aq_transm'] = aq_tr
    store['ooip'] = Noi
    store['rock_comp'] = rock_comp
    store['gas_prd'] = gas_prd
    store['gas_prd_eff'] = gas_prd_eff
    store['gas_inj_eff'] = gas_inj_eff
    store['water_prd_eff'] = water_prd_eff
    store['water_inj_eff'] = water_inj_eff
    store['root_method'] = root_method
    store['interp_kind'] = interp_kind

    return store

What type of dcc.Store are you using?

@jinnyzor, I am using session. Do you think local would be better?

By the way @AIMPED and @jinnyzor thanks for the help, the prevent initial call works to keep the selectedData in the store.

But the graph selectedData still doesn’t hold anything. and I can’t reselect it on the graph for the user to see. unless I have to implement it with a call back. Graph component doesn’t have persisted data.

But this will do for now. Thanks!

Are you using it in the callback to draw the figures?