I have a Div that populates with a DashTable after I click the ‘Submit’ button. I also have a ‘Clear’ button that I want to use so that the Div gets cleared. It’s the same div, but I don’t know how to include it in my app.callback so that it works, I get an ‘list is out of range’ error.
app.layout = html.Div(children=[
html.H1(children='Project'),
dcc.Dropdown(id='my-identifier-type'),
dcc.Input(id='my-identifier'),
html.Button('Submit',id='submit-button'),
html.Button('Clear',id='clear-button'),
html.Div(id='charac_table',
style={'marginBottom': 50, 'marginTop': 25, 'width':'20%', 'display':'block'})
@app.callback(
Output(‘charac_table’, ‘children’),
[Input(‘submit-button’, ‘n_clicks_timestamp’),
Input(‘my-identifier-type’, ‘value’),
Input(‘my-identifier’, ‘value’),
Input(‘clear-button’,‘n_clicks’)])
def update_my_view(click_timestamp, identifier_type, identifier_input, x_click):
if x_click > 0:
my_display = 'none'
return html.Div(style={'display':my_display})
elif click_timestamp > ((datetime.now() - timedelta(seconds=0.5)).timestamp()*1000):
my_display = 'inline-block'
return html.Div([
html.Div(id='charac_table'),
dash_table.DataTable(
id = 'characteristics',
columns = [{"name":i, "id":i} for i in des_table.columns],
data = des_table.to_dict("rows"),
style_header={
'backgroundColor': 'White',
'fontWeight': 'bold'
},
style_table={'maxwidth': '10'},
style_cell={'width':'10'},
sorting_type='multi',
selected_rows=[])
],
style={'width':'80%', 'display':my_display, 'margin-bottom': '1.0em'})