I created a generatable charts that saved in postgresql. And I added some buttons like a delete button for every charts. It look like this
How can I use the delete button? I tried to create another callback, but I think it didn’t read every button. If I click the other delete button it’s printing “None” but, if I click the last one it’s printing “1”. Is there another solution? I wanted to use the delete button for every chart. I want to get the value from the dcc.input if I click the button. I’m open with any suggestion to improve my work.
app.layout = html.Div(id='graphs', children=[
])
@app.callback(Output('graphs', 'children'),
Input('graphs', 'children'))
def update_extend_traces_traceselect(child):
fig = go.Figure()
fig.add_trace(
go.Bar(
x=xval,
y=yval,
name=barname,
marker_color=barcolor,
orientation=orientation,
marker_line_color=markerlinecolor,
marker_line_width=float(markerlinewidth)
))
fig.update_layout(
title=title,
)
child.append(html.Div(
dcc.Input(
id="charts-id",
type="text",
value=chart_ID[i]
),
html.Button('Delete', id='delete-chart', n_clicks=0),
dcc.Graph(figure=fig,
config={
'displayModeBar': False,
})],
style={'height': '550px', 'width': '550px', 'margin': '10px',
'border': '1px solid'}))
return child
@app.callback(Output('delete-chart', 'n_clicks'),
Input('delete-chart', 'n_clicks'),
State('charts-id', 'value')
)
def delete(n_clicks, value):
print(n_clicks) //only for the last chart works//
print(value) //printing the value of the last dcc.input//
if "OverviewChart" == '__main__':
app.run_server(debug=True)