I can create a default chart by creating this button which loads the chart with the default settings. But not sure how to go about it for the selection options - buttons, sliders etc.
Chart
chart = sns.jointplot(x=select_box_X, y=select_box_Y, data=Scatter_graph_data, alpha=alpha, height=height, ratio=ratio_chart, space=space, xlim=(0.0,1.01), ylim=(0.0,1.01), color=color)
if default_options:
chart = sns.jointplot(x=select_box_X, y=select_box_Y, data=Scatter_graph_data, alpha=.4, height=8.0, ratio=7, space=.4, xlim=(0.0,1.01), ylim=(0.0,1.01)) #, color=color)
Is there a way to make these options go back to the original/default value upon pushing the default button?
Update
So I tried recreating the icons after the button is pushed, though was not entirely sure how to replace this old icons with these new ones. It seemed to create a new set of icons which makes sense. Employing this method seems to work with the chart though not so much for the these filter options. Will keep tweaking and updating but any help would be appreciated. Thanks!
SORTED
Using placeholder worked. Final code:
placeholder = st.empty()
with placeholder:
select data for default graph
axes_options = st.beta_columns(3)
#Options for default chart
scatter_choices = st.beta_columns([4,4,4,4,1])
#select x-axis
select_box_X = axes_options[0].selectbox('Select x-axis', data_col, key=1)
#select y-axis
select_box_Y = axes_options[1].selectbox('Select y-axis', data_col, key=2)
# Control dimensions of chart
default = 'navy'
color = ...
color = axes_options[2].selectbox('Choose color', options=color, key=1)
height = scatter_choices[0].slider('Height of chart', min_value=0.0, max_value=30.0, step=.1, value=8.0, key=1)
# Rati
ratio_chart = scatter_choices[1].slider('Ratio', min_value=0, max_value=30, step=1, value=7, key=2)
# Space
space = scatter_choices[2].slider('Space', min_value=0.0, max_value=1.0, step=.1, value=.4, key=3)
# Show cuts/shapes of plots
alpha = scatter_choices[3].slider('Plot density', min_value=0.0, max_value=1.0, step=.1, value=.4, key=4)
# Default settings
default_options = scatter_choices[4].button('Default', key=1)
# Additional options
options = scatter_choices[4].checkbox('Additional Options', key=5)
scatter_choices = st.beta_columns([4,4,3,3,2])
Chart....
# Default button pushed
if default_options:
with placeholder:
.... Repeat code but without keys
1 Like
A correction for the above. It seems I did not quite understand how to use the placeholder but figured it out. The above did not replace all the necessary elements. In fact it left out the x and y-axis inputs. The remedy was as follows:
## create 'space' to replace old inputs with new inputs
axes_placeholder = st.empty()
scatter_choices_placeholder = st.empty()
#### create space for the replacement of the chart
chart_placeholder = st.empty()
##### select data for default graph. Store inputs in this space (replace 'st.' with placeholder variable)
axes_options = axes_placeholder.beta_columns(3)
### Options for default chart
scatter_choices = scatter_choices_placeholder.beta_columns([4,4,4,4,1])
.... (inputs for chart)
chart_placeholder.pyplot()
#### New inputs/Default
#### i want this to replace the above when the button is pushed
if default_options:
#select data for default graph but replace old inputs with new inputs
axes_options = axes_placeholder.beta_columns(3)
#Options for default chart but replace old inputs with new inputs
scatter_choices = scatter_choices_placeholder.beta_columns([4,4,4,4,1])
... (data inputs for new options)
# chart plot (new one replaced with old one)
chart_placeholder.pyplot(chart, use_container_width=True)