How to prevent the reloading of the whole page when I let the user to perform an action

Hello everyone,

I am building a page which let the user to run a query against my database, once I have the data I would like to perform a simple exploratory data analysis of the data.

The problem arise when, at button of the page, I let the user choose any column of the data set with a selectbox to make a countplot. When the user perform that action, every single element of my page is rendered again and it creates a really poor user experience with the page.

When I load the data I use the decorator of cache with the allow_output_mutation option set true

Hi @Capi_hacendado -

Re-running top-to-bottom is the core of the Streamlit execution model, and where you don’t want to re-run things you can use st.cache (which you’ve indicated you’re using). So it sounds like you are doing what you’re supposed to.

Can you post a code snippet that demonstrates the problem?

Best,
Randy

Hi @randyzwitch thank you so much for answer.

You can see here a snippet of my code

            with st.beta_expander('Grafical distribution of the columns', expanded=False):
            fig_hist, ax = plt.subplots(figsize=(50, 30))
            ax.xaxis.set_major_formatter(plt.FuncFormatter(format_func))
            ax.yaxis.set_major_formatter(plt.FuncFormatter(format_func))
            df.hist(bins=30, color='r', ax=ax, xrot=90)
            fig_hist.tight_layout()
            st.pyplot(fig_hist, clear_figure=True)
        
        with st.beta_expander('Explore Categorical Columns', expanded=False):
            fig_count = plt.figure(figsize=[25, 12])
            hue_column = None
            column = st.selectbox('Choose Column', ['<select>'] + df.columns.tolist())
            if not column == '<select>':
                a = sns.countplot(x=column, hue=hue_column, data=df)
                a.set_xlabel(f'{column}', fontsize=24)
                a.set_ylabel(f'Count', fontsize=24)
                st.pyplot(fig_count, clear_figure=True)

In my use case scenario, moreover to show a distribution of the columns dataframe, I want to show a count plot of the categorical columns. So my problem comes when an user choose an specific column, the whole page will rerun, producing a terrible user experience. Most probably I am making a bad use of it

Again thank you for your answer