I created a generatable charts that saved in postgresql. I used For Loop in this. I added some buttons like a delete button for every charts. It look like this
My desired output is like this: If I clicked the delete button, get the value of dcc.input of that chart which is the ID from the postgresql and then call the charts model
ChartsModels().objects.get(id=value of dccinput).delete()
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):
i = 0
for b in barData:
fig = go.Figure()
fig.add_trace(
go.Bar(
x=[d['value'] for d in y][0],
y=newdatetime,
name=barname[i],
marker_color=barcolor[i],
orientation=orientation[i],
marker_line_color=markerlinecolor[i],
marker_line_width=float(markerlinewidth[i])
))
else:
fig = go.Figure()
fig.add_trace(
go.Bar(
y=[d['value'] for d in y][0],
x=newdatetime,
name=barname[i],
marker_color=barcolor[i],
orientation=orientation[i],
marker_line_color=markerlinecolor[i],
marker_line_width=float(markerlinewidth[i])
))
fig.update_layout(
# barmode=barmode[i],
xaxis_title=xtitle[i],
yaxis_title=ytitle[i],
title=title[i],
showlegend=ast.literal_eval(showlegend[i]),
xaxis_showgrid=ast.literal_eval(showgrid[i]),
yaxis_showgrid=ast.literal_eval(showgrid[i]),
xaxis_showticklabels=ast.literal_eval(showticklabels[i]),
yaxis_showticklabels=ast.literal_eval(showticklabels[i])
)
child.append(html.Div(id="div-id", children=[dcc.Input(
id="charts-id",
type="text",
value=chart_ID[i]
), html.Button('EDIT', id='edit-chart',
style={'margin': '5px'}),
html.Button('Delete', id='hiddenButton', n_clicks=0,
style={'margin': '5px'}),
dcc.Graph(figure=fig,
config={
'displayModeBar': False,
})],
style={'height': '550px', 'width': '550px', 'margin': '10px',
'border': '1px solid'}))
i = i + 1
app.clientside_callback(
"""
function removeChart(n1, children) {
console.log(n1)
return ''}
""",
Output('output_div', 'children'), Input(
'hiddenButton', 'n_clicks'), State('graphs', 'children')
)
@app.callback(Output('output_div', 'children'),
[Input('hiddenButton', 'n_clicks')],
[State('charts-id', 'value')],
)
def update_output(clicks, input_value):
if clicks is not None:
print(clicks, input_value)
if "OverviewChart" == '__main__':
app.run_server(debug=True)
The problem it’s only getting the last value of dcc.Input. If I clicked the other delete button from other charts. It’s printing a None