Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Updating data to dash table

I am trying to get data from a csv and display it using dash table. I want to interact with one column and then changing another column accordingly (Subtracting value of ‘manual input’ column from ‘recommended’ column and storing the answer to ‘available’ column)

I have got the result of subtractions and can view the data frame on cmd but I do not understand how to write it to Output of Callback function and after trying following code it shows error loading dependencies.

Q1

DF= pd.read_csv(
‘data.csv’
)

app.layout = html.Div(children=[
html.H4(‘Manual recommendation’),
html.Div([
html.Div(id=‘Table’,children=
dt.DataTable(
rows=DF.to_dict(‘records’),
filterable=True,
sortable=True,
selected_row_indices=[],
id=‘edit-table’,
),
),
]),
],)

@app.callback(Output(‘edit-table’, ‘rows’),
[Input(‘edit-table’, ‘rows’)],
)

def update_table(rows):
df = pd.DataFrame(rows)
df[‘available’] = df[‘recommendation’].astype(int) - df[‘manual input’].astype(int)
return df

You don’t need to use a callback, just create your dataframe and then pass it in the ‘rows’ attribute of dt.DataTable
Callback would be usefull only if you wish to dynamically change your datatable.

Actually I am willing to make dynamic changes on data.
Initially I have a dataframe like this: Q2
which I am displaying in ‘rows’ attribute of dt.Datatable.

Now I want to enter numbers in ‘manual input’ column which should call the callback function and after making calculations ( subtraction : “df[‘available slots’] = df[‘recommendation rounded’].astype(int) - df[‘manual input’].astype(int)”) I want to display complete dataframe in the same rows attribute of that table.
I am confused about the ‘Output’ and ‘Input’ of callbacks because the table id will be same and also rows attribute will be same in Output and Input of callback as I am taking input from a table and want to print output to that same table.