How to avoid refreshing/updating charts on irrelevant changes

Hi there,

I built a small app, which is constructed as follows:

  1. Load small DataFrame from a Database (with st.cache)
  2. Use results from the 1. to be selected in a dropdown (wich st.cache, although itโ€™s a small function)
  3. Based on selection in dropdown load data from the Internet (with st.cache)
  4. Transform data from 3 (with st.cache)
  5. Get Altair_Chart based von transformed data from 4. (with st.cache)
  6. st.alt_chart(5.)
    โ€ฆ
  7. Another Dropdown (analogous to 2) with no relevant effect on the other functions, especially not on the Graph:

Result: Every time I select something from the second dropdown (which should have no effect on the rest of the code), the charts from step 5 is loaded/plotted. This costs about a second, since it is a lot of data. Nevertheless, I would like to implement even more charts. How can I avoid a refreshing of charts, which are not touched, by other customizations. This would help to improve performance, since I donโ€™t have to wait for so long every time, I change anything?

import streamlit as st
import chartfunctions as dc
import helperfunctions as hf

st.title('App Title')
logo = hf.get_logo(r'C:/users/user/Logo.PNG')
st.sidebar.image(logo, format='PNG', width=280)

indexes = hf.get_indexes()                                                                              #st.cache
term = st.sidebar.selectbox('Select Index:', indexes['name'])
log_ret = st.sidebar.selectbox('Select Return Type:', ['return', 'log_return'])
ticker = hf.get_ticker(indexes, term)                                                                #st.cache

df_index_data = hf.get_index_data(ticker)                                                      #st.cache
df_desc, df_melt = hf.transform_df_indexdaily(df_index_data, log_ret, ticker, melt=True) #st.cache

st.altair_chart(dc.getindexChart1(df_index_data, log_ret))                              #st.cache

st.subheader('Index Comparison')
term_comp = st.selectbox('Select another Index to compare with:', indexes['name'])
# this selection should be relevant for any charts above
1 Like

This is also more problematic in larger pages when you change something on the bottom and you have to wait until everything is rendered all the way to that point.

It would be great to use the key of the widget and with a condition block a chunk of code being refresh or updated on selection of the widget.

3 Likes

Hey @mariusgarbowski,

Unfortunately, right now thatโ€™s not supported in Streamlit.

However, one of our major goals for 2020 is Streamlit plugin system which will give you the ability to write arbitrary JavaScript code and insert it into your app. This opens the door for a lot of possibilities for custom solutions to layout, visualization, interactivity with chart/maps/tables, and other unique needs of your app. You can help design this feature or follow its progress over there https://github.com/streamlit/streamlit/issues/327.

And thanks for using Streamlit!

2 Likes