Skip to content

Commit

Permalink
Minor typos and clarifications (#1215)
Browse files Browse the repository at this point in the history
* Button guide typo

* Clarify imported classes

* Add LazyFrame to caching table
  • Loading branch information
sfc-gh-dmatthews authored Jan 7, 2025
1 parent 39e3c29 commit f04fc75
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions content/develop/concepts/app-design/custom-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions content/develop/concepts/architecture/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down

0 comments on commit f04fc75

Please sign in to comment.