Hi there,
I built a small app, which is constructed as follows:
- Load small DataFrame from a Database (with st.cache)
- Use results from the 1. to be selected in a dropdown (wich st.cache, although it’s a small function)
- Based on selection in dropdown load data from the Internet (with st.cache)
- Transform data from 3 (with st.cache)
- Get Altair_Chart based von transformed data from 4. (with st.cache)
- st.alt_chart(5.)
… - 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