I have some functions set up like this to try to create interactive Plotly figures that can be changed based on buttons or Select menus:
select_combat_stat = pn.widgets.Select(name='Combat Stat Selection',
options=['dmg_taken', 'dmg_dealt', 'dmg_mitigated','dmg_healed'],
value='dmg_taken')
def total_combat_stat(cntxt):
gb = pc_combat_stats_df.groupby('pc').sum().reset_index()
fig = px.bar(gb,
x='pc',
y=cntxt,
color='pc',
color_discrete_map = pc_color_map,
title=f'Total Campaign-wide {cntxt} Per Character')
return fig
party_combat_box = pn.WidgetBox(pn.Column(pn.Row(pn.pane.Markdown(f"# Party Combat Visualizations")),
pn.Row(pn.bind(total_combat_stat,select_combat_stat), pn.bind(total_combat_stat_per_session,select_combat_stat)),
align="start", sizing_mode="stretch_width"))
And then I have the dashboard itself set up like:
template = pn.template.FastListTemplate(
......
main=[pn.Row(party_box),
pn.Row(party_combat_box)],
....
)
template.show()
template.servable();
It shows up correctly upon first launching the server locally. I select a new option from the dropdown and the figure doesn’t change. But if I select a different option from the dropdown a second time, it shows the correct figure for the last option I chose.
Example: It starts out with dmg_taken as the default value. I select dmg_healed, and it continues showing dmg_taken figure. I select dmg_mitigated, and it will show the figure for dmg_healed, my last option chosen. I select dmg_taken again, it will show the dmg_mitigated figure. Etc, etc.
Any ideas for a fix?