Hi @empet ,
I have a similar problem. I just tried your solution too. But this time, I have three traces. Two graphs are in the same plot. Third one is a table. Here is my code:
def make_multi_plot(df1, df2, item_list):
date_time = str(datetime.datetime.now())[0:16].replace(':','-').replace(' ','_')
with open('Model_Raporu_'+date_time+'.html', 'a') as f:
fig = make_subplots(rows=2,
cols=1,
shared_xaxes=True,
vertical_spacing=0.05,
specs = [[{}], [{"type": "table"}]]
)
for item_id in item_list:
trace1 = go.Scatter(
x=df1.loc[df1.ITEM_ID.isin([item_id])].SALES_DATE,
y=df1.loc[df1.ITEM_ID.isin([item_id])].y,
mode='lines+markers',
name = "orjinal - " + str(item_id))
fig.append_trace(trace1,1,1)
trace1x = go.Scatter(
x=df1.loc[df1.ITEM_ID.isin([item_id])].SALES_DATE,
y=df1.loc[df1.ITEM_ID.isin([item_id])].y_hat,
mode='lines+markers',
name = "tahmin - " + str(item_id))
fig.append_trace(trace1x,1,1)
trace2 = go.Table(
header = dict(
values = df2[df2.ITEM_ID.isin([item_id])].columns.tolist(),
font = dict(size=10),
align = "left"),
cells = dict(
values = [df2[df2.ITEM_ID.isin([item_id])][k].tolist() for k in df2[df2.ITEM_ID.isin([item_id])].columns[:]],
align = "left"
)
)
fig.append_trace(trace2,2,1)
Ld = len(fig.data)
Lc = len(item_list)
for k in range(3, Ld):
fig.update_traces(visible=False, selector = k)
def create_layout_button(k, item_id):
visibility= [False]*3*Lc
for tr in [3*k, 3*k+1]:
visibility[tr] =True
return dict(label = item_id,
method = 'restyle',
args = [{'visible': visibility,
'title': item_id,
'showlegend': True}])
fig.update_layout(
updatemenus=[go.layout.Updatemenu(
active = 0,
buttons = [create_layout_button(k, item_id) for k, item_id in enumerate(item_list)],
x = 0.5,
y = 1.15
)
],
title = 'Model Raporu',
template = 'plotly_dark',
height=800
)
fig.show()
f.write(fig.to_html(full_html=False, include_plotlyjs='cdn'))
When change the dropdown button, only the graph above changes. But table remains same. I could not change it by dropdown. Here is the image:
How can I change the table with dropdown?