Interrupt current run on change in user input

Dear community,
I started using streamlit six weeks ago and I am absolutely amazed how fast one can progress in building complex webapps!

The app I am developing imports large data sets using xarray, transforms them and generates heatmap plots using altair. So far I could keep up a good performance using the caching on time consuming functions. However, now that the input data becomes larger I am facing new issues which brings me to my current question:

Can I interrupt the current evaluation of the app when the filters for my data (implemented via st.multiselect) change? Currently, I select a data set and the app starts plotting the data set. This will take a few seconds even with caching. When I change my filters on the data, they will only be applied after the first plot is completed. And if I change multiple filters this can be really frustrating.

If needed, I can try to implement a minimal working example with some sleeps. Just let me know in case my question was not precise enough.

Thanks for your help!

EDIT: here comes some minimal code example

import streamlit as st
from time import sleep

dataset = st.sidebar.multiselect('Dataset', ['data1', 'data2'])

if dataset:
    filter1 = st.sidebar.multiselect('Filter 1', ['a', 'b', 'c', 'd'])
    filter2 = st.sidebar.multiselect('Filter 2', ['1', '2', '3', '4'])

    with st.spinner('Updating plot...'):
        st.subheader('filter1 value')
        st.subheader('filter2 value')

1 Like