Hi,
I have looked over the internet for solutions to the duplicate callback. I cannot find a solution that works for me.
I have one graph:
dcc.Graph(
id="IVgraph",
style={"width": "350px", "height" : "400px"}, # "100%"},
figure={
"data": data,
"layout": dict(
paper_bgcolor=banner_color['light'], #["dark"],
plot_bgcolor=banner_color['light'], #["dark"],
automargin=True,
font=dict(color=text_color['dark'], size=12), #theme], size=12),
xaxis={
"color": banner_color['light'], #["dark"],
"gridcolor": banner_color['light'], #["dark"],
},
yaxis={
"color": banner_color['light'], #["dark"],
"gridcolor": banner_color['light'], #["dark"],
},
),
},
#animate=True
),
I have one callback:
@app.callback(
Output('IVgraph', 'figure'),
[ Input('graph-update', 'n_intervals')]
)
def update_graph_scatter(n):
global X
global Y
global q
conn1 = sqlite3.connect(GlobalVars.DatabaseLocation, timeout=20)
cdbcon1 = conn1.cursor()
cdbcon1.execute("SELECT Azimuth FROM plotdata ORDER BY rowid DESC LIMIT 1")
newdata = cdbcon1.fetchone()
newdata1 = newdata[0]
if (len(X) < 30):
X.append(X[-1]+1)
Y.append(newdata1)
data1 = go.Scatter(
x=list(X),
y=list(Y),
name='IVgraph',
mode= 'lines+markers'
)
layout1 = dict(
xaxis =
{
"range" : [ len(X), 0],#[0, len(X) ],
"color": grid_color["dark"],
"gridcolor": grid_color["dark"],
"tickmode" : "auto",
"nticks" : 5,
"title" : "Time Elapsed (min)",
},
yaxis =
{
"range" : [0,360],
"fixedrange" : True,
},
plot_bgcolor=banner_color["dark"],
paper_bgcolor=banner_color["dark"]
)
cdbcon1.close()
conn1.close()
return {'data': [data1],
'layout' : layout1}
The definition for graph update is:
dcc.Interval(id=‘graph-update’, interval = 120000, n_intervals = 110),
This results in the following error:
In the callback for output(s):
IVgraph.figure
Output 0 (thisIVgraph.figure) is already in use.
Any given output can only have one callback that sets it.
To resolve this situation, try combining these into
one callback function, distinguishing the trigger
by using dash.callback_context
if necessary.
if I change the name of the callback as shown:
@app.callback(
Output(thisIVgraph’, ‘figure’),
[ Input(‘graph-update’, ‘n_intervals’)]
)
but keep the id as shown:
dcc.Graph(
id=“IVgraph”,
The error becomes:
In the callback for output(s):
thisIVgraph.figure
Output 0 (thisIVgraph.figure) is already in use.
Any given output can only have one callback that sets it.
To resolve this situation, try combining these into
one callback function, distinguishing the trigger
by using dash.callback_context
if necessary.
IU am not sure what I am doing wring.
Any help or guidance is appreciated.
Malcolm