Cheat sheet - Streamlit Docs

PHOTO EMBED

Sun Jul 02 2023 17:51:56 GMT+0000 (Coordinated Universal Time)

Saved by @rooterbot #python

# E.g. Dataframe computation, storing downloaded data, etc.
>>> @st.cache_data
... def foo(bar):
...   # Do something expensive and return data
...   return data
# Executes foo
>>> d1 = foo(ref1)
# Does not execute foo
# Returns cached item by value, d1 == d2
>>> d2 = foo(ref1)
# Different arg, so function foo executes
>>> d3 = foo(ref2)
# Clear all cached entries for this function
>>> foo.clear()
# Clear values from *all* in-memory or on-disk cached functions
>>> st.cache_data.clear()
content_copyCOPY

Optimize performance

https://docs.streamlit.io/library/cheatsheet