The following code works by itself but I have a "TypeError: unhashable type: 'set'" when it's in my plotly graph. Can you help me out with this ? I never worked with set or frozenset.
Thanks a lot !
code that works be itself :
updatemenus = []
for n, ecole in enumerate(liste_ecole):
visible = [False]*len(liste_ecole)
visible[n] = True
temp_dict = dict(label = str(liste_ecole),
method = 'update',
args = [{"visible" : visible,
{"title"} : "Prévisions des effectifs pour {}".format(liste_ecole)}])
updatemenus.append(temp_dict)
code inside my plotly graph :
fig = go.Figure([
go.Scatter(
name='Effectif réel',
x=df2['date_str'],
y=df2['reel'],
mode='markers+lines',
marker=dict(color="#1e3d59"),
line=dict(width=1),
showlegend=True,
text=df2['jour']
),
go.Scatter(
name='Prévision algorithme',
x=df2['date_str'],
y=df2['output'],
mode='markers+lines',
marker=dict(color="#ff6e40", size=4),
line=dict(width=2),
showlegend=True,
text=df2['jour']
)
])
fig.layout.plot_bgcolor = '#f5f0e1'
updatemenus = []
for n, ecole in enumerate(liste_ecole):
visible = [False]*len(liste_ecole)
visible[n] = True
temp_dict = dict(label = str(liste_ecole),
method = 'update',
args = [{"visible" : visible,
{"title"} : "Prévisions des effectifs pour {}".format(liste_ecole)}]) **#THIS IS WHERE I GOT MY ERROR**
updatemenus.append(temp_dict)
fig.update_layout(
updatemenus=list([dict(buttons= list_updatemenus)]),
yaxis_title="Nombre de convives",
hovermode="x",
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=1.02,
xanchor="left",
y=0.75,
yanchor="top"
)
fig.update_xaxes(tickformat='%d-%b-%Y')
fig.update_xaxes(rangeslider_visible=True)
fig.show()
This error has nothing to do with Plotly. You can't have a
set
(literal) as a key in adict
because aset
isn't hashable.And you don't need a set there, so just replace
{"title"}
with"title"
(a hashablestr
).