I have an app that connects to BigQuery using st.cache_data
like so:
def bigquery_connection():
@st.cache_data(ttl=600)
def run_query(query):
query_job = client.query(query)
raw_data = query_job.result()
# Convert to list of dicts. Required for st.experimental_memo to hash the return value.
data = [dict(data) for data in raw_data]
return data
However, if I include a widget (i.e., a radio option or select box) and interact with it, it re-runs the app every time.
From the docs, it states that st.cache_data
will alleviate this:
See st.cache_data above? Without it, Streamlit would run the query every time the app reruns (e.g. on a widget interaction). With st.cache_data, it only runs when the query changes or after 10 minutes (that’s what ttl is for). Watch out: If your database updates more frequently, you should adapt ttl or remove caching so viewers always see the latest data. Learn more in Caching.
Maybe I am not understanding this correctly or understanding how connections work in Streamlit but shouldn’t using st.cache_data
not re-run the app each time?
I also tried st.cache_resource
but the same thing happens.