Hi! I am working on a Streamlit app that involves fetching and analyzing a large dataset of sports data for a user.
Obviously, given the fact that Streamlit reruns the page on each input change, i want to be caching the dataset from the first time it is fetched. However, when i tag the function with st.cache, it seems to get stuck in its execution… I just see “Running” and it never stops. This is occuring specifically for the ‘load_league_data’ function. I can see in my terminal that the next lines of code are being executed, but this is not reflecting on the streamlit app
season = st.selectbox('Season', [2021, 2020, 2019])
league_id = st.text_input('Enter your league ID:')
def main():
st.title('Fantasy App')
st.write('Use machine learning to show you how bad you are at fantasy football')
if st.button('get data'):
with st.spinner("fetching league data"):
league = load_league_data(league_id, season)
st.write(league)
@st.cache
def load_league_data(leag_id, season):
if len(leag_id) == 8:
league = League(leag_id, season)
return league
def populate_team_df(league):
teams = league.teams
team_objs = []
team_names = []
for i, team in teams.items():
team_objs.append(team)
team_names.append(team.teamName)
teams_dict = {'team_obj': team_objs, 'team_name': team_names}
return pd.DataFrame(teams_dict)
if __name__ == '__main__':
main()