Does DataTable editable=True property updates the Dictionary on which it is based?

If I set editable=True in a DataTable, does it update respective Dictionary values automatically?

Hello @akhurana,

No, the only way that it would update the dictionary on the server side is if you set it up to do so in a callback.

Hello @jinnyzor ,
Thanks for prompt reply.
I am also using dcc.Interval and the Dictionary & DataTable keeps updating every 2 seconds.
Can you please give some hint as to how to set it up so that respective Dictionary Values gets updated in a callback?

Sure, for that we will need to see a little bit of your code.

Could you please provide an MRE?

Hello @jinnyzor ,

Based on the MRE guidelines here is the code with sample data:

import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import dash_table

import pandas as pd

Positions = [{'symbol':'abc', 'position': 'long', 'buyprice': 20, 'sellprice': 0, 'stoploss': 18, 'target': 25, 'CMP': 19},
             {'symbol':'def', 'position': 'long', 'buyprice': 30, 'sellprice': 0, 'stoploss': 25, 'target': 35, 'CMP': 31}

app = dash.Dash(__name__)

app.layout = html.Div([
	html.H1(id='my_h1', children="Positions"),
	html.Div([dash_table.DataTable(id='my-table-df-1', columns=[], data=[], editable=True)]),
    dcc.Interval(id='table-update', interval=5000, n_intervals=0, disabled=False)

        Output('my-table-df-1', 'columns'),
        Output('my-table-df-1', 'data'),
	[Input('table-update', 'n_intervals')]
def update_table(n):
	global Positions
	global dfPositions

	dfPositions = pd.DataFrame(Positions)
	my_table_df_1_columns = [{"name": i, "id": i} for i in dfPositions.columns]
	my_table_df_1_data = Positions

	return (my_table_df_1_columns, my_table_df_1_data)

if __name__ == '__main__':

CMP gets updated based on Brokers API.

Purpose is to edit StopLoss and Target in DataTable which should get updated in Dictionary as well and so in next auto updation DataTable should display the updated values.


You are trying to update information from two different sources, is that correct?

Doing this, makes it tricky.

Hello @jinnyzor ,

In that case remove CMP field which is updated based on Broker API. How to update then dictionary based on editing done in DataTable to StopLoss and Target fields? Some hint would be sufficient rather than full solution regarding updation of Dictionary behind DataTable.

Hey @akhurana,

Ok, your table’s data can trigger an update any time that you edit, via the timestamp, the data is presented in a dictionary. So you can just save the dictionary any time there is an edit.

Check out the info here:

Hello @jinnyzor ,

I have seen that page earlier, but could not figure it out how to do it. I will explore that again based on the suggestion you have given. Thanks a lot.

1 Like