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

1 Like

I believe this is a limitation of Streamlit. Currently, some app designs cannot be accomplished… which is a pitty.

It would be incredibly useful to allow the programmer decide which parts of the page will be reloaded.

1 Like

Hello @GitHunter0,

This is currently being designed, and we would be grateful if you could provide us with examples of app/workflow you would like to design without too much challenges!

Have a nice day,
Fanilo

1 Like

Hey @andfanilo ,

I’m really glad you are working on that. Streamlit has a bright future.

For example:
I tried to design an app that a part of it requires a password to access. However, with every new user input value, the page is reloaded and the password is asked again.

Thank you, and keep the great work

:+1: great !

In the meantime, you could check the st.forms method (blog post) to prevent page reloading on every user input, using instead a submit button to run the script login. Though you would still need to save that you are connected inside the unofficial SessionState.

:balloon: Fanilo

Cool @andfanilo , I was precisely using st.forms (great feature by the way), but not SessionState. Once it becomes robust and official, it will definitively put Streamlit on another level.

Thank you for the feedback

1 Like