go.layout.updatemenu.Button update method failed to apply restyle and relayout changes.
Hello, I use the example from https://plotly.com/python/custom-buttons/#update-button to test update method, but it failed to pefrom restyle and relayout simultaneously. For example, when I click button "low", the lines won't change, and the title keep in the same. BTW, I show the figure in notebook. In my own code, I want to update the trace and shapes together, but It only updates the traces when using 'update', and only update shapes when using relayout. Such as: ` buttons = []
for ind, (subgraph_name, subgraph_lines) in enumerate(subgraph_name_line_tup):
is_visible = [True if i in subgraph_lines else False for i in range(num_lines)]
if blocks_list is not None:
args = {'shapes[{}].visible'.format(i): block_show_mapper[ind][i] for i in range(len(block_show_mapper[ind]))}
else:
args = {}
method = 'update'
args['visible'] = is_visible
button = dict(label=subgraph_name, method=method, args=[args])
buttons.append(button)
`
Looking forward for you answer. Thanks a lot.
The buttons are inactive because the annotation updates refer to inexistent positions in the plot window. xaxis type is linear and its ticklabels are indices (x=df.index). The first dict in the lists high_annotations and low_annotations refers to a position consisting in x= some date (x="2016-03-01", y=df.High.mean()), respectively (x="2015-05-01", y=df.Low.mean()), but no date type data are involved in the four trace definitions.
These requirements "confused plotly.js`", and the trace update could not be done.
To get it work, just remove the first dict from both these lists.
THX! But in my own example, I got six traces and 15 blocks, I use the dropdown button to select which two traces were displayed and which five blocks were showed, and use the 'update' method, where 'trace' is need to update data and 'block' is need to update layout. But, I only got my traces updated. Here are my partial code:
subgraph_name_line_tup = [('line1', [0, 1]), ('line2', [0, 2]), ('line3, [0, 3])]
block_show_mapper = [[True, True, True, True, True, False, False, False, False, False, False, False, False, False, False],
[False, False, False, False, False, True, True, True, True, True, False, False, False, False, False],
[False, False, False, False, False, False, False, False, False, False, True, True, True, True, True]]
buttons = []
for ind, (subgraph_name, subgraph_lines) in enumerate(subgraph_name_line_tup):
is_visible = [True if i in subgraph_lines else False for i in range(num_lines)]
if blocks_list is not None:
args = {'shapes[{}].visible'.format(i): block_show_mapper[ind][i] for i in range(len(block_show_mapper[ind]))}
else:
args = {}
method = 'update'
args['visible'] = is_visible
button = dict(label=subgraph_name, method=method, args=[args])
buttons.append(button)
annotations = []
updatemenus = []
updatemenus.append(dict(buttons=buttons,
direction='down',
type='dropdown',
# showactive=True,
x=0.050,
xanchor='left',
y=1.13,
yanchor='top')
)
annotations.append(dict(text='select lines: ', x=0, xref='paper', y=1.10, yref='paper', align='left', showarrow=False))
fig.update_layout(annotations=annotations)
fig.update_layout(updatemenus=updatemenus)
I'm sorry, but from a partial code, and no data for testing I cannot express any opinion on why it doesn't work. It's not important for debugging, the code that leads to the buttons definition, but their effective contents, because most of the time the error is in button args. Please search Plotly community https://community.plotly.com/c/graphing-libraries/5 for restyle and relayout, to find out more on this methods.
Finally, I solved my problem. As in my example, I want to update shapes (layout) and traces (data), I put them on the same dict. But the truth is that we should seperate them into two dict in one list, and append the update traces part first, then the update shapes part.