I have 2 buttons that affect the same scatter. The first button affect the ‘i’ and the second the ‘j’ in : ((np.swapaxes(AllData[j, :, :, :], 1, 2))[i, :, :])
The problem is when I clic on a dropdown button, it will set the other variable (i or j) at 0.
I think that I can solve it using a callback function right ? It’s the first time that I use it and I don’t really know how to do it…
I suggest to create a Callback function and call it at the end of my code in : fig.show(CallBackFct)
?
Thank you for helping
# Set all the Data in ALlData matrix
AllData = np.zeros((NbreOfBanks, NbreMeasure, NbreOfSamples, NbreOfNozzles))
for i in range(NbreMeasure):
AllData[:, i, :, :] = load_json(FolderPath, files[FirstToSee + i], "Sensing")
# Create the figure
fig = go.Figure(go.Scatter(x=list(range(0, NbreOfSamples)), y=((np.swapaxes(AllData[0, :, :, :], 1, 2))[0, 0, :]),
mode="lines"))
for k in range(1, NbreOfNozzles):
fig.add_scatter(x=list(range(0, NbreOfSamples)), y=((np.swapaxes(AllData[0, :, :, :], 1, 2))[NbreSelect, k, :]), mode="lines")
fig.update_layout(width=1600, height=900, title="Sensing Measure", title_x=0.5,
xaxis_title="Measure number", yaxis_title="ADC Value")
# Create button for selected JSON
buttons = []
for i in range(NbreMeasure):
buttons.append(dict(method='update',
label=files[FirstToSee + i],
visible=True,
args=[{'y': ((np.swapaxes(AllData[j, :, :, :], 1, 2))[i, :, :]),
'x': list(range(0, NbreOfSamples)),
'type': 'scatter'}, [0]],
)
)
# Create button for each bank option
buttons_bank = []
BankName = ['BankA', 'BankB', 'BankC', 'BankD']
for j in range(NbreOfBanks):
buttons_bank.append(dict(method='update',
label=str(BankName[j]),
visible=True,
args=[{'y': ((np.swapaxes(AllData[j, :, :, :], 1, 2))[i, :, :]),
'x': list(range(0, NbreOfSamples)),
'type': 'scatter'}, [0]],
)
)
# Add the dropdown button to the layout)
fig.update_layout(
updatemenus=[
dict(
buttons=buttons,
direction='down',
showactive=True,
x=0.1,
xanchor='left',
y=1.1,
yanchor='top'
),
dict(
buttons=buttons_bank,
direction='down',
showactive=True,
x=0,
xanchor='left',
y=1.1,
yanchor='top'
)
])
# add dropdown menus to the figure
fig.update_layout(showlegend=True)
fig.show()```