Black Lives Matter. Please consider donating to Black Girls Code today.

Saving changes in table

So… I’ve got a drop-down upon which an editable table updates and produces a chart… very fancy :smiley:
But when I make changes into the table, change the drop down value, and change it back, the changes disappear.

Any way I can ensure they don’t?


1 Like

I’ve seen this before, I think in the case where you have components like dcc.Input, dcc.Dropdown etc in your layout, but they are not yet registered with any callback. Perhaps try seeing if this might be the case.

Thanks for the input. but I don’t think i quiet understand your point. :blush:

The dropdown updates the table perfectly, and the table is editable. The thing is, the changes I make in the table are not saved anywhere, and hence when I change the dropdown value and change it back, that change is not saved.

I don’t think its an error, I just need to save changes and I dont know how or where.

Ah I see, sorry, didn’t realise you just wanted to save the values.

How many people are using this app? Assuming you want the saved values to be the state that all users of the app see, then this isn’t too hard. Per-user sessions become a bit trickier though.

The safest way to do this (without per-user sessions) is to change your app so that it reads off the current value for the dropdown and any other saved data from a saved file (eg csv), then your callback that updates the graph also has to update this file with the current value.

This also means that you also need to make the value of app.layout a function that returns the layout. This way, each user will get the current state

eg, something along the lines of:

def make_layout():
    options = get_options_from_file()
    return html.Div([
        dcc.Dropdown(id='dropdown', options=options)

app.layout = make_layout

What about the per-user session scenario?

Thanks Ned, I appreciate the input. what I understand is that this would keep the last selected option in the dropdown list saved and visible for all users.

What I’m trying to do though is save the changes in the table, not the dropdown. The thing is, we cannot use global variables, i.e. I cannot change the dataframe shown on dash using dash’s table.

I tried using the methods presented here: , but that means ill have a call back where the table is the input and the intermediate value is the input, and another callback where the intermediate value is the input and the table is the input, which leads to an Error loading dependencies (naturally).

Check out this thread: Capture window/tab closing event

1 Like