diff --git a/content/library/api/performance/experimental-memo.md b/content/library/api/performance/experimental-memo.md index 89eb52324..e3cf6b340 100644 --- a/content/library/api/performance/experimental-memo.md +++ b/content/library/api/performance/experimental-memo.md @@ -68,6 +68,7 @@ Supported static `st` elements in cache-decorated functions include: - `st.alert` - `st.altair_chart` - `st.area_chart` +- `st.audio` - `st.bar_chart` - `st.ballons` - `st.bokeh_chart` @@ -84,8 +85,12 @@ Supported static `st` elements in cache-decorated functions include: - `st.expander` - `st.experimental_get_query_params` - `st.experimental_set_query_params` +- `st.experimental_show` +- `st.form` +- `st.form_submit_button` - `st.graphviz_chart` - `st.help` +- `st.image` - `st.info` - `st.json` - `st.latex` @@ -101,33 +106,9 @@ Supported static `st` elements in cache-decorated functions include: - `st.table` - `st.text` - `st.vega_lite_chart` +- `st.video` - `st.warning` -Forms and media elements are not supported in cache-decorated functions. If you use them, the code will only be called when we detect a cache "miss", which can lead to unexpected results. Which is why Streamlit will throw a `CachedStFunctionWarning`, like the one below: - -```python -import numpy as np -import pandas as pd -import streamlit as st - -@st.experimental_memo -def load_data(rows): - chart_data = pd.DataFrame( - np.random.randn(rows, 10), - columns=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"], - ) - # Contains an unsupported st command - st.video("https://www.youtube.com/watch?v=wpDuY9I2fDg") - # Streamlit will throw a CachedStFunctionWarning - - return chart_data - -df = load_data(20) -st.dataframe(df) -``` - - - ### Replay input widgets in cache-decorated functions In addition to static elements, functions decorated with `@st.experimental_memo` can also contain [input widgets](/library/api-reference/widgets)! Replaying input widgets is disabled by default. To enable it, you can set the `experimental_allow_widgets` parameter for `@st.experimental_memo` to `True`. The example below enables widget replaying, and shows the use of a checkbox widget within a cache-decorated function. diff --git a/content/library/api/performance/experimental-singleton.md b/content/library/api/performance/experimental-singleton.md index 45fd08d85..21c678000 100644 --- a/content/library/api/performance/experimental-singleton.md +++ b/content/library/api/performance/experimental-singleton.md @@ -45,6 +45,7 @@ Supported static `st` elements in cache-decorated functions include: - `st.alert` - `st.altair_chart` - `st.area_chart` +- `st.audio` - `st.bar_chart` - `st.ballons` - `st.bokeh_chart` @@ -61,8 +62,12 @@ Supported static `st` elements in cache-decorated functions include: - `st.expander` - `st.experimental_get_query_params` - `st.experimental_set_query_params` +- `st.experimental_show` +- `st.form` +- `st.form_submit_button` - `st.graphviz_chart` - `st.help` +- `st.image` - `st.info` - `st.json` - `st.latex` @@ -78,31 +83,9 @@ Supported static `st` elements in cache-decorated functions include: - `st.table` - `st.text` - `st.vega_lite_chart` +- `st.video` - `st.warning` -Forms and media elements are not supported in cache-decorated functions. If you use them, the code will only be called when we detect a cache "miss", which can lead to unexpected results. Which is why Streamlit will throw a `CachedStFunctionWarning`, like the one below: - -```python -import numpy as np -import pandas as pd -import streamlit as st -from transformers import AutoModel - -@st.experimental_singleton -def get_model(model_type): - # Contains an unsupported st command - st.video("https://www.youtube.com/watch?v=wpDuY9I2fDg") - # Streamlit will throw a CachedStFunctionWarning - - # Create a model of the specified type - return AutoModel.from_pretrained(model_type) - -bert_model = get_model("distilbert-base-uncased") -st.help(bert_model) # Display the model's docstring -``` - - - ### Replay input widgets in cache-decorated functions In addition to static elements, functions decorated with `@st.experimental_singleton` can also contain [input widgets](/library/api-reference/widgets)! Replaying input widgets is disabled by default. To enable it, you can set the `experimental_allow_widgets` parameter for `@st.experimental_singleton` to `True`. The example below enables widget replaying, and shows the use of a checkbox widget within a cache-decorated function.