Skip to content

Commit f9d7136

Browse files
Additional stubs; logical design grouping
1 parent f8cbf1d commit f9d7136

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+217
-170
lines changed

content/get-started/fundamentals/advanced-concepts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The basic idea behind caching is to store the results of expensive function call
1515

1616
To cache a function in Streamlit, you need to apply a caching decorator to it. You have two choices:
1717

18-
- `st.cache_data` is the recommended way to cache computations that return data. Use `st.cache_data` when you use a function that returns a serializable data object (e.g. str, int, float, DataFrame, dict, list). **It creates a new copy of the data at each function call**, making it safe against [mutations and race conditions](/develop/concepts/caching#mutation-and-concurrency-issues). The behavior of `st.cache_data` is what you want in most cases – so if you're unsure, start with `st.cache_data` and see if it works!
18+
- `st.cache_data` is the recommended way to cache computations that return data. Use `st.cache_data` when you use a function that returns a serializable data object (e.g. str, int, float, DataFrame, dict, list). **It creates a new copy of the data at each function call**, making it safe against [mutations and race conditions](/develop/concepts/logical-design/caching#mutation-and-concurrency-issues). The behavior of `st.cache_data` is what you want in most cases – so if you're unsure, start with `st.cache_data` and see if it works!
1919
- `st.cache_resource` is the recommended way to cache global resources like ML models or database connections. Use `st.cache_resource` when your function returns unserializable objects that you don’t want to load multiple times. **It returns the cached object itself**, which is shared across all reruns and sessions without copying or duplication. If you mutate an object that is cached using `st.cache_resource`, that mutation will exist across all reruns and sessions.
2020

2121
Example:
@@ -36,7 +36,7 @@ Before running the code within `long_running_function`, Streamlit checks its cac
3636

3737
<Image src="/images/caching-high-level-diagram.png" caption="Streamlit's two caching decorators and their use cases." alt="Streamlit's two caching decorators and their use cases. Use st.cache_data for anything you'd store in a database. Use st.cache_resource for anything you can't store in a database, like a connection to a database or a machine learning model." />
3838

39-
For more information about the Streamlit caching decorators, their configuration parameters, and their limitations, see [Caching](/develop/concepts/caching).
39+
For more information about the Streamlit caching decorators, their configuration parameters, and their limitations, see [Caching](/develop/concepts/logical-design/caching).
4040

4141
## Session State
4242

@@ -103,7 +103,7 @@ df = conn.query("select * from my_table")
103103
st.dataframe(df)
104104
```
105105

106-
Of course, you may be wondering where your username and password go. Streamlit has a convenient mechanism for [Secrets management](/develop/concepts/configuration/secrets-management). For now, let's just see how `st.connection` works very nicely with secrets. In your local project directory, you can save a `.streamlit/secrets.toml` file. You save your secrets in the toml file and `st.connection` just uses them! For example, if you have an app file `streamlit_app.py` your project directory may look like this:
106+
Of course, you may be wondering where your username and password go. Streamlit has a convenient mechanism for [Secrets management](/develop/concepts/logical-design/secrets-management). For now, let's just see how `st.connection` works very nicely with secrets. In your local project directory, you can save a `.streamlit/secrets.toml` file. You save your secrets in the toml file and `st.connection` just uses them! For example, if you have an app file `streamlit_app.py` your project directory may look like this:
107107

108108
```bash
109109
your-LOCAL-repository/

content/get-started/fundamentals/main-concepts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ This can happen in two situations:
8989
- Whenever a user interacts with widgets in the app. For example, when dragging
9090
a slider, entering text in an input box, or clicking a button.
9191

92-
Whenever a callback is passed to a widget via the `on_change` (or `on_click`) parameter, the callback will always run before the rest of your script. For details on the Callbacks API, please refer to our [Session State API Reference Guide](/develop/api-reference/caching-and-state/session-state#use-callbacks-to-update-session-state).
92+
Whenever a callback is passed to a widget via the `on_change` (or `on_click`) parameter, the callback will always run before the rest of your script. For details on the Callbacks API, please refer to our [Session State API Reference Guide](/develop/api-reference/control-flow/session-state#use-callbacks-to-update-session-state).
9393

9494
And to make all of this fast and seamless, Streamlit does some heavy lifting
9595
for you behind the scenes. A big player in this story is the
@@ -293,7 +293,7 @@ st.text_input("Your name", key="name")
293293
st.session_state.name
294294
```
295295

296-
Every widget with a key is automatically added to Session State. For more information about Session State, its association with widget state, and its limitations, see [Session State API Reference Guide](/develop/api-reference/caching-and-state/session-state).
296+
Every widget with a key is automatically added to Session State. For more information about Session State, its association with widget state, and its limitations, see [Session State API Reference Guide](/develop/api-reference/control-flow/session-state).
297297

298298
### Use checkboxes to show/hide data
299299

content/get-started/fundamentals/tutorials/create-an-app.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ transformational.
178178
<Tip>
179179

180180
Whenever you have a long-running computation in your code, consider
181-
refactoring it so you can use `@st.cache_data`, if possible. Please read [Caching](/develop/concepts/caching) for more details.
181+
refactoring it so you can use `@st.cache_data`, if possible. Please read [Caching](/develop/concepts/logical-design/caching) for more details.
182182

183183
</Tip>
184184

content/kb/tutorials/chat.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ slug: /develop/tutorials/llms/build-conversational-apps
77

88
## Introduction
99

10-
The advent of large language models like GPT has revolutionized the ease of developing chat-based applications. Streamlit offers several [Chat elements](/develop/api-reference/chat), enabling you to build Graphical User Interfaces (GUIs) for conversational agents or chatbots. Leveraging [session state](/develop/concepts/session-state) along with these elements allows you to construct anything from a basic chatbot to a more advanced, ChatGPT-like experience using purely Python code.
10+
The advent of large language models like GPT has revolutionized the ease of developing chat-based applications. Streamlit offers several [Chat elements](/develop/api-reference/chat), enabling you to build Graphical User Interfaces (GUIs) for conversational agents or chatbots. Leveraging [session state](/develop/concepts/logical-design/session-state) along with these elements allows you to construct anything from a basic chatbot to a more advanced, ChatGPT-like experience using purely Python code.
1111

1212
In this tutorial, we'll start by walking through Streamlit's chat elements, `st.chat_message` and `st.chat_input`. Then we'll proceed to construct three distinct applications, each showcasing an increasing level of complexity and functionality:
1313

14-
1. First, we'll [Build a bot that mirrors your input](#build-a-bot-that-mirrors-your-input) to get a feel for the chat elements and how they work. We'll also introduce [session state](/develop/concepts/session-state) and how it can be used to store the chat history. This section will serve as a foundation for the rest of the tutorial.
14+
1. First, we'll [Build a bot that mirrors your input](#build-a-bot-that-mirrors-your-input) to get a feel for the chat elements and how they work. We'll also introduce [session state](/develop/concepts/logical-design/session-state) and how it can be used to store the chat history. This section will serve as a foundation for the rest of the tutorial.
1515
2. Next, you'll learn how to [Build a simple chatbot GUI with streaming](#build-a-simple-chatbot-gui-with-streaming).
1616
3. Finally, we'll [Build a ChatGPT-like app](#build-a-chatgpt-like-app) that leverages session state to remember conversational context, all within less than 50 lines of code.
1717

@@ -99,7 +99,7 @@ Pretty straightforward, right? Now let's combine `st.chat_message` and `st.chat_
9999

100100
## Build a bot that mirrors your input
101101

102-
In this section, we'll build a bot that mirrors or echoes your input. More specifically, the bot will respond to your input with the same message. We'll use `st.chat_message` to display the user's input and `st.chat_input` to accept user input. We'll also use [session state](/develop/concepts/session-state) to store the chat history so we can display it in the chat message container.
102+
In this section, we'll build a bot that mirrors or echoes your input. More specifically, the bot will respond to your input with the same message. We'll use `st.chat_message` to display the user's input and `st.chat_input` to accept user input. We'll also use [session state](/develop/concepts/logical-design/session-state) to store the chat history so we can display it in the chat message container.
103103

104104
First, let's think about the different components we'll need to build our bot:
105105

@@ -322,7 +322,7 @@ pip install openai streamlit
322322

323323
### Add OpenAI API key to Streamlit secrets
324324

325-
Next, let's add our OpenAI API key to [Streamlit secrets](/develop/concepts/configuration/secrets-management). We do this by creating `.streamlit/secrets.toml` file in our project directory and adding the following lines to it:
325+
Next, let's add our OpenAI API key to [Streamlit secrets](/develop/concepts/logical-design/secrets-management). We do this by creating `.streamlit/secrets.toml` file in our project directory and adding the following lines to it:
326326

327327
```toml
328328
# .streamlit/secrets.toml

content/kb/tutorials/databases/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ slug: /develop/tutorials/databases
77

88
These step-by-step guides demonstrate how to connect Streamlit apps to various databases & APIs.
99
They use Streamlit's [Secrets management](/deploy/streamlit-community-cloud/deploy-your-app/secrets-management) and
10-
[caching](/develop/concepts/caching) to provide secure and fast data access.
10+
[caching](/develop/concepts/logical-design/caching) to provide secure and fast data access.
1111

1212
<DataSourcesContainer>
1313
<DataSourcesCard href="/develop/tutorials/databases/aws-s3">

content/kb/tutorials/databases/aws-s3.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ slug: /develop/tutorials/databases/aws-s3
77

88
## Introduction
99

10-
This guide explains how to securely access files on AWS S3 from Streamlit Community Cloud. It uses [Streamlit FilesConnection](https://github.com/streamlit/files-connection), the [s3fs](https://github.com/dask/s3fs) library and optionally Streamlit's [Secrets management](/develop/concepts/configuration/secrets-management).
10+
This guide explains how to securely access files on AWS S3 from Streamlit Community Cloud. It uses [Streamlit FilesConnection](https://github.com/streamlit/files-connection), the [s3fs](https://github.com/dask/s3fs) library and optionally Streamlit's [Secrets management](/develop/concepts/logical-design/secrets-management).
1111

1212
## Create an S3 bucket and add a file
1313

@@ -110,7 +110,7 @@ for row in df.itertuples():
110110
st.write(f"{row.Owner} has a :{row.Pet}:")
111111
```
112112

113-
See `st.connection` above? This handles secrets retrieval, setup, result caching and retries. By default, `read()` results are cached without expiring. In this case, we set `ttl=600` to ensure the file contents is cached for no longer than 10 minutes. You can also set `ttl=0` to disable caching. Learn more in [Caching](/develop/concepts/caching).
113+
See `st.connection` above? This handles secrets retrieval, setup, result caching and retries. By default, `read()` results are cached without expiring. In this case, we set `ttl=600` to ensure the file contents is cached for no longer than 10 minutes. You can also set `ttl=0` to disable caching. Learn more in [Caching](/develop/concepts/logical-design/caching).
114114

115115
If everything worked out (and you used the example file given above), your app should look like this:
116116

content/kb/tutorials/databases/bigquery.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ for row in rows:
135135
st.write("✍️ " + row['word'])
136136
```
137137

138-
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](/develop/concepts/caching).
138+
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](/develop/concepts/logical-design/caching).
139139

140140
Alternatively, you can use pandas to read from BigQuery right into a dataframe! Follow all the above steps, install the [pandas-gbq](https://pandas-gbq.readthedocs.io/en/latest/index.html) library (don't forget to add it to `requirements.txt`!), and call `pandas.read_gbq(query, credentials=credentials)`. More info [in the pandas docs](https://pandas.pydata.org/docs/reference/api/pandas.read_gbq.html).
141141

content/kb/tutorials/databases/gcs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ slug: /develop/tutorials/databases/gcs
77

88
## Introduction
99

10-
This guide explains how to securely access files on Google Cloud Storage from Streamlit Community Cloud. It uses [Streamlit FilesConnection](https://github.com/streamlit/files-connection), the [gcsfs](https://github.com/fsspec/gcsfs) library and Streamlit's [Secrets management](/develop/concepts/configuration/secrets-management).
10+
This guide explains how to securely access files on Google Cloud Storage from Streamlit Community Cloud. It uses [Streamlit FilesConnection](https://github.com/streamlit/files-connection), the [gcsfs](https://github.com/fsspec/gcsfs) library and Streamlit's [Secrets management](/develop/concepts/logical-design/secrets-management).
1111

1212
## Create a Google Cloud Storage bucket and add a file
1313

@@ -135,7 +135,7 @@ for row in df.itertuples():
135135
st.write(f"{row.Owner} has a :{row.Pet}:")
136136
```
137137

138-
See `st.connection` above? This handles secrets retrieval, setup, result caching and retries. By default, `read()` results are cached without expiring. In this case, we set `ttl=600` to ensure the file contents is cached for no longer than 10 minutes. You can also set `ttl=0` to disable caching. Learn more in [Caching](/develop/concepts/caching).
138+
See `st.connection` above? This handles secrets retrieval, setup, result caching and retries. By default, `read()` results are cached without expiring. In this case, we set `ttl=600` to ensure the file contents is cached for no longer than 10 minutes. You can also set `ttl=0` to disable caching. Learn more in [Caching](/develop/concepts/logical-design/caching).
139139

140140
If everything worked out (and you used the example file given above), your app should look like this:
141141

content/kb/tutorials/databases/mongodb.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ for item in items:
9696
st.write(f"{item['name']} has a :{item['pet']}:")
9797
```
9898

99-
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](/develop/concepts/caching).
99+
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](/develop/concepts/logical-design/caching).
100100

101101
If everything worked out (and you used the example data we created above), your app should look like this:
102102

content/kb/tutorials/databases/mssql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ for row in rows:
186186

187187
```
188188

189-
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](/develop/concepts/caching).
189+
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](/develop/concepts/logical-design/caching).
190190

191191
If everything worked out (and you used the example table we created above), your app should look like this:
192192

content/kb/tutorials/databases/mysql.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ slug: /develop/tutorials/databases/mysql
77

88
## Introduction
99

10-
This guide explains how to securely access a **_remote_** MySQL database from Streamlit Community Cloud. It uses [st.connection](/develop/api-reference/connections/st.connection) and Streamlit's [Secrets management](/develop/concepts/configuration/secrets-management). The below example code will **only work on Streamlit version >= 1.28**, when `st.connection` was added.
10+
This guide explains how to securely access a **_remote_** MySQL database from Streamlit Community Cloud. It uses [st.connection](/develop/api-reference/connections/st.connection) and Streamlit's [Secrets management](/develop/concepts/logical-design/secrets-management). The below example code will **only work on Streamlit version >= 1.28**, when `st.connection` was added.
1111

1212
## Create a MySQL database
1313

@@ -35,7 +35,7 @@ INSERT INTO mytable VALUES ('Mary', 'dog'), ('John', 'cat'), ('Robert', 'bird');
3535

3636
## Add username and password to your local app secrets
3737

38-
Your local Streamlit app will read secrets from a file `.streamlit/secrets.toml` in your app's root directory. Learn more about [Streamlit secrets management here](/develop/concepts/configuration/secrets-management). Create this file if it doesn't exist yet and add the database name, user, and password of your MySQL server as shown below:
38+
Your local Streamlit app will read secrets from a file `.streamlit/secrets.toml` in your app's root directory. Learn more about [Streamlit secrets management here](/develop/concepts/logical-design/secrets-management). Create this file if it doesn't exist yet and add the database name, user, and password of your MySQL server as shown below:
3939

4040
```toml
4141
# .streamlit/secrets.toml
@@ -93,7 +93,7 @@ for row in df.itertuples():
9393
st.write(f"{row.name} has a :{row.pet}:")
9494
```
9595

96-
See `st.connection` above? This handles secrets retrieval, setup, query caching and retries. By default, `query()` results are cached without expiring. In this case, we set `ttl=600` to ensure the query result is cached for no longer than 10 minutes. You can also set `ttl=0` to disable caching. Learn more in [Caching](/develop/concepts/caching).
96+
See `st.connection` above? This handles secrets retrieval, setup, query caching and retries. By default, `query()` results are cached without expiring. In this case, we set `ttl=600` to ensure the query result is cached for no longer than 10 minutes. You can also set `ttl=0` to disable caching. Learn more in [Caching](/develop/concepts/logical-design/caching).
9797

9898
If everything worked out (and you used the example table we created above), your app should look like this:
9999

0 commit comments

Comments
 (0)