From f04fc750dccc5a65b697128d85c2b22adffcbd20 Mon Sep 17 00:00:00 2001 From: Debbie Matthews Date: Mon, 6 Jan 2025 17:06:40 -0800 Subject: [PATCH] Minor typos and clarifications (#1215) * Button guide typo * Clarify imported classes * Add LazyFrame to caching table --- .../concepts/app-design/button-behavior-and-examples.md | 2 +- content/develop/concepts/app-design/custom-classes.md | 4 ++-- content/develop/concepts/architecture/caching.md | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/content/develop/concepts/app-design/button-behavior-and-examples.md b/content/develop/concepts/app-design/button-behavior-and-examples.md index 4382e3772..bf03470c3 100644 --- a/content/develop/concepts/app-design/button-behavior-and-examples.md +++ b/content/develop/concepts/app-design/button-behavior-and-examples.md @@ -306,7 +306,7 @@ begin.text_input('Name', key='name') ### Buttons to add other widgets dynamically -When dynamically adding widgets to the page, make sure to use an index to keep the keys unique and avoid a `DuplicateWidgetID` error. In this example, we define a function `display_input_row` which renders a row of widgets. That function accepts an `index` as a parameter. The widgets rendered by `display_input_row` use `index` within their keys so that `dispaly_input_row` can be executed multiple times on a single script rerun without repeating any widget keys. +When dynamically adding widgets to the page, make sure to use an index to keep the keys unique and avoid a `DuplicateWidgetID` error. In this example, we define a function `display_input_row` which renders a row of widgets. That function accepts an `index` as a parameter. The widgets rendered by `display_input_row` use `index` within their keys so that `display_input_row` can be executed multiple times on a single script rerun without repeating any widget keys. ```python import streamlit as st diff --git a/content/develop/concepts/app-design/custom-classes.md b/content/develop/concepts/app-design/custom-classes.md index 11323bd8c..3d7839425 100644 --- a/content/develop/concepts/app-design/custom-classes.md +++ b/content/develop/concepts/app-design/custom-classes.md @@ -19,7 +19,7 @@ We begin by covering some general-purpose patterns you can use for different typ ### Pattern 1: Define your class in a separate module -This is the recommended, general solution. If possible, move class definitions into their own module file and import them into your app script. As long as you are not editing the file where your class is defined, Streamlit will not re-import it with each rerun. Therefore, if a class is defined in an external file and imported into your script, the class will not be redefined during the session. +This is the recommended, general solution. If possible, move class definitions into their own module file and import them into your app script. As long as you are not editing the files that define your app, Streamlit will not re-import those classes with each rerun. Therefore, if a class is defined in an external file and imported into your script, the class will not be redefined during the session, unless you are actively editing your app. #### Example: Move your class definition @@ -74,7 +74,7 @@ st.write(isinstance(st.session_state.my_instance, MyClass)) st.button("Rerun") ``` -Streamlit only reloads code in imported modules when it detects the code has changed. Thus, if you are actively editing the file where your class is defined, you may need to stop and restart your Streamlit server to avoid an undesirable class redefinition mid-session. +Streamlit only reloads code in imported modules when it detects the code has changed. Thus, if you are actively editing your app code, you may need to start a new session or restart your Streamlit server to avoid an undesirable class redefinition. ### Pattern 2: Force your class to compare internal values diff --git a/content/develop/concepts/architecture/caching.md b/content/develop/concepts/architecture/caching.md index db126c294..b77324c16 100644 --- a/content/develop/concepts/architecture/caching.md +++ b/content/develop/concepts/architecture/caching.md @@ -289,6 +289,7 @@ Or if you're lazy and don't want to think too much, look up your use case or ret | Running an ML model (inference) | pandas.DataFrame, str, int, dict, list | st.cache_data | | Creating or processing images | PIL.Image.Image, numpy.ndarray | st.cache_data | | Creating charts | matplotlib.figure.Figure, plotly.graph_objects.Figure, altair.Chart | st.cache_data (but some libraries require st.cache_resource, since the chart object is not serializable – make sure not to mutate the chart after creation!) | +| Lazy computations | polars.LazyFrame | st.cache_resource (but may be better to use st.cache_data on the collected results) | | Loading ML models | transformers.Pipeline, torch.nn.Module, tensorflow.keras.Model | st.cache_resource | | Initializing database connections | pyodbc.Connection, sqlalchemy.engine.base.Engine, psycopg2.connection, mysql.connector.MySQLConnection, sqlite3.Connection | st.cache_resource | | Opening persistent file handles | \_io.TextIOWrapper | st.cache_resource |