Hi,
Iām struggling with updating plots through an on_click callback in a session state.
The callback executes as it should (generates new data frame and plots) and I can access updated plots by a different name in the session state but it doesnāt update already initially generated plots, breaking the flow.
Is there a simpler way to execute this than the code below?
Thanks!
Code snippet:
page2_container = st.container()
def update_figures():
objectName.value = new_value
updated_data = objectName.generate_data() # with new_value
updated_plot_a = objectName.generate_plot_a(updated_data)
updated_plot_b = objectName.generate_plot_b(updated_data)
# I want to display these updated plots
st.session_state.figures.update({'PLOT_A': updated_plot_a})
st.session_state.figures.update({'PLOT_B': updated_plot_b})
with st.sidebar:
value = st.number_input(
label='Select value',
min_value=0,
max_value=100,
value=0,
on_change=update_figures) # callback
objectName = moduleName.className(...)
data_diff = testObject.generate_data()
plot_a = testObject.generate_plot_a(data_diff)
plot_b = testObject.generate_plot_b(data_diff)
st.session_state.figures.update({'PLOT_A': plot_a})
st.session_state.figures.update({'PLOT_B': plot_b})
with page2_container:
with st.container():
left, right = st.columns([1, 1])
with left:
st.plotly_chart(st.session_state.figures['PLOT_A']) # displays initially generated plot
with right:
st.plotly_chart(st.session_state.figures['PLOT_B']) # displays initially generated plot