I am trying to use the selected rows feature of dash datatable to perform something on click of a button but I can’t seem to extract any selected row data. This is my current code:
html.Div([html.H3("Table of unverfied users", style = {"color":"grey"}),
dash_table.DataTable(id = "email-auth",
columns = [{"name":i, "id":i} for i in columns_to_verify],
data = users_to_verify.to_dict("records"),
#for page size i.e. pages page_size = 10
page_size = 50,
page_action = "none",
#add row selectivity
row_selectable = "multi",
#store selected rows
selected_rows = [],
fixed_rows = {"headers":True},
style_header = {"backgroundColor":"blue",
"color": "white",
"border":"1px solid black"},
style_cell = {"textAlign":"left",
"border":"1px solid black"},
style_table={ "overflowY":"auto",
"overflowX":"auto"})],
style = {"display":"block",
"width":"80%",
"marginTop":10,
"marginBottom":40,
"margin-left":"auto",
"margin-right":"auto",
"padding":"10px"}),
html.Div([
html.Button("Verify", id = "but-veify", n_clicks = 0),
html.Button("Remove", id = "but-remove", n_clicks = 0),
html.Div(id = "hidden-div", style = {"display":"none"})])
@app.callback(
Output("hidden-div", "style_data_conditional"),
[Input("email-auth", "columns"),
Input("email-auth", "selected_rows")]
)
def update_styles(columns, selected_rows):
print("I am triggered")
# return[{"if":{"derived_virtual_indeces":i},
# "background_color":"grey"
# } for i in selected_rows]
selected_rows = [columns[i] for i in selected_rows]
print(selected_rows)
style = {"display":"none"}
return style
Ideall I would like to tale selected row data, i.e. user id’s from each row, then on click of either verify or remove it would perform a given action i.e. On click of Verify, all ids would be verified such as:
def verify(user_df):
user_ids = list(user_df["uid"])
ref = db.reference("/users/")
for user_id in user_ids:
ref.child(user_id).child("Verified").set(True)
While for Remove it would be:
def delete_users(user_df):
user_ids = list(user_df["uid"])
for user_id in user_ids:
auth.delete_user(uid)
When the selected rows are selected and the button is clicked. Any advice would be appreciated.