Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f5e3f56
Restructures menu to test ideas
snehankekre Jul 29, 2021
7625dd2
Add section to topic guides
snehankekre Jul 29, 2021
823d372
Merge branch 'main' of https://github.com/streamlit/docs into devrel-…
snehankekre Aug 2, 2021
e3d880e
Merge branch 'main' of https://github.com/streamlit/docs into devrel-…
snehankekre Aug 3, 2021
77e60cb
Reorders top level categories in menu
snehankekre Aug 3, 2021
1fa3df2
Reorganizes menu
snehankekre Aug 11, 2021
0f4a813
Updates navigation menu and populates content
snehankekre Aug 16, 2021
87e0be5
Merge branch 'main' of https://github.com/streamlit/docs into devrel-…
snehankekre Aug 16, 2021
ecaba5a
Remove Update and Support sections from navbar
snehankekre Aug 31, 2021
d355853
Add kb directory
randyzwitch Aug 31, 2021
977c2ea
Updates API reference and sources.list
snehankekre Sep 1, 2021
23d8c31
Maps most pages in ols docs to new site
snehankekre Sep 1, 2021
1f6a9d5
Maps most pages in old docs to new site
snehankekre Sep 1, 2021
47d152e
Add canonical tag for versioned urls
Sep 1, 2021
2496e26
Remove condition for canonical tags on versioned urls
Sep 1, 2021
467853e
Modify canonical url based on version numbering
Sep 1, 2021
c49f75e
Streamlit Cloud Platform to Streamlit Cloud
snehankekre Sep 2, 2021
5dfe531
Merge branch 'seo-adjustments' of https://github.com/streamlit/docs i…
snehankekre Sep 2, 2021
90a8bc3
Merge seo adjustments branch - canonical
snehankekre Sep 2, 2021
8bb8a14
Add canonical tag on homepage
Sep 2, 2021
2e89964
Merge branch 'seo-adjustments' of https://github.com/streamlit/docs i…
snehankekre Sep 3, 2021
ccb75e8
Updates docstrings and removes filler text from RefCards
snehankekre Sep 3, 2021
396e210
Adds st.echo to API ref and fixes broken links in Get Started
snehankekre Sep 3, 2021
2edb4ad
Fix broken links in all Get Started section pages + Streamlit Cloud
snehankekre Sep 3, 2021
4ec293c
Fix broken links in all pages of Advanced Features section
snehankekre Sep 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added content/kb/.keep
Empty file.
2 changes: 1 addition & 1 deletion content/support/faq.md → content/kb/faq.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Frequently Asked Questions
slug: /support/faq
slug: /kb/faq
---

# Frequently Asked Questions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Caching issues
slug: /support/troubleshooting/caching-issues
slug: /kb/troubleshooting/caching-issues
---

# Caching issues
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: How to clean install Streamlit
slug: /support/troubleshooting/clean-install
slug: /kb/troubleshooting/clean-install
---

# How to clean install Streamlit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Remote app not loading
slug: /support/troubleshooting/remote-start
slug: /kb/troubleshooting/remote-start
---

# App is not loading when running remotely
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Sanity checks
slug: /support/troubleshooting/sanity-checks
slug: /kb/troubleshooting/sanity-checks
---

# Sanity checks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Troubleshooting
slug: /support/troubleshooting
slug: /kb/troubleshooting
---

# Troubleshooting
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Create a data explorer app
slug: /tutorials/data-explorer
slug: /kb/tutorials/data-explorer
---

# Create a data explorer app
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Connect Streamlit to AWS S3
slug: /tutorials/databases/aws-s3
slug: /kb/tutorials/databases/aws-s3
---

# Connect Streamlit to AWS S3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Connect Streamlit to Google BigQuery
slug: /tutorials/databases/bigquery
slug: /kb/tutorials/databases/bigquery
---

# Connect Streamlit to Google BigQuery
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Connect to a database
slug: /tutorials/databases
title: Connect to data sources
slug: /kb/tutorials/databases
---

# Connect Streamlit to a database
# Connect Streamlit to data sources

These step-by-step guides demonstrate how to connect Streamlit apps to various databases & APIs.
They use Streamlit's [secrets management](../deploy_streamlit_app.html#secrets-management) and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Connect Streamlit to Google BigQuery
slug: /tutorials/databases/mongodb
slug: /kb/tutorials/databases/mongodb
---

# Connect Streamlit to MongoDB
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Connect Streamlit to MySQL
slug: /tutorials/databases/mysql
slug: /kb/tutorials/databases/mysql
---

# Connect Streamlit to MySQL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Connect Streamlit to PostgreSQL
slug: /tutorials/databases/postgresql
slug: /kb/tutorials/databases/postgresql
---

# Connect Streamlit to PostgreSQL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Connect Streamlit to a private Google Sheet
slug: /tutorials/databases/private-gsheet
slug: /kb/tutorials/databases/private-gsheet
---

# Connect Streamlit to a private Google Sheet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Connect Streamlit to a public Google Sheet
slug: /tutorials/databases/public-gsheet
slug: /kb/tutorials/databases/public-gsheet
---

# Connect Streamlit to a public Google Sheet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Connect Streamlit to Tableau
slug: /tutorials/databases/tableau
slug: /kb/tutorials/databases/tableau
---

# Connect Streamlit to Tableau
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Visualising rent prices with Streamlit
slug: /tutorials/rent-prices
slug: /kb/tutorials/rent-prices
---

# Visualising rent prices with Streamlit
Expand Down
4 changes: 4 additions & 0 deletions content/library/advanced-features/advanced-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Advanced Features
slug: /library/advanced-features
---
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: Optimize performance with st.cache
slug: /topic-guides/caching
slug: /library/advanced-features/caching
---

# Optimize performance with st.cache

Streamlit provides a caching mechanism that allows your app to stay performant even when loading data from the web, manipulating large datasets, or performing expensive computations. This is done with the [`@st.cache`](api.html#streamlit.cache) decorator.
Streamlit provides a caching mechanism that allows your app to stay performant even when loading data from the web, manipulating large datasets, or performing expensive computations. This is done with the [`@st.cache`](/library/api-reference/performance#stcache) decorator.

When you mark a function with the [`@st.cache`](api.html#streamlit.cache) decorator, it tells Streamlit that whenever the function is called it needs to check a few things:
When you mark a function with the [`@st.cache`](/library/api-reference/performance#stcache) decorator, it tells Streamlit that whenever the function is called it needs to check a few things:

1. The input parameters that you called the function with
2. The value of any external variable used in the function
Expand All @@ -18,7 +18,7 @@ If this is the first time Streamlit has seen these four components with these ex

The way Streamlit keeps track of changes in these components is through hashing. Think of the cache as an in-memory key-value store, where the key is a hash of all of the above and the value is the actual output object passed by reference.

Finally, [`@st.cache`](api.html#streamlit.cache) supports arguments to configure the cache's behavior. You can find more information on those in our [API reference](api.md).
Finally, [`@st.cache`](/library/api-reference/performance#stcache) supports arguments to configure the cache's behavior. You can find more information on those in our [API reference](/library/api-reference).

Let's take a look at a few examples that illustrate how caching works in a Streamlit app.

Expand All @@ -43,7 +43,7 @@ st.write("Result:", res)

Try pressing **R** to rerun the app, and notice how long it takes for the result to show up. This is because `expensive_computation(a, b)` is being re-executed every time the app runs. This isn't a great experience.

Let's add the [`@st.cache`](api.html#streamlit.cache) decorator:
Let's add the [`@st.cache`](/library/api-reference/performance#stcache) decorator:

```python
import streamlit as st
Expand Down Expand Up @@ -196,7 +196,7 @@ res = expensive_computation(a, b)
st.write("Result:", res)
```

Even though `inner_func()` is not annotated with [`@st.cache`](api.html#streamlit.cache), when we edit its body we cause a "Cache miss" in the outer `expensive_computation()`.
Even though `inner_func()` is not annotated with [`@st.cache`](/library/api-reference/performance#stcache), when we edit its body we cause a "Cache miss" in the outer `expensive_computation()`.

That's because Streamlit always traverses your code and its dependencies to verify that the cached values are still valid. This means that while developing your app you can edit your code freely without worrying about the cache. Any change you make to your app, Streamlit should do the right thing!

Expand Down Expand Up @@ -228,7 +228,7 @@ What you'll see:
- If you move the slider to a number Streamlit hasn't seen before, you'll have a cache miss again. And every subsequent rerun with the same number will be a cache hit, of course.
- If you move the slider back to a number Streamlit has seen before, the cache is hit and the app is fast as expected.

In computer science terms, what is happening here is that [`@st.cache`](api.html#streamlit.cache) is [memoizing](https://en.wikipedia.org/wiki/Memoization) `expensive_computation(a, b)`.
In computer science terms, what is happening here is that [`@st.cache`](/library/api-reference/performance#stcache) is [memoizing](https://en.wikipedia.org/wiki/Memoization) `expensive_computation(a, b)`.

But now let's go one step further! Try the following:

Expand All @@ -242,7 +242,7 @@ This happens because the Streamlit cache is global to all users. So everyone con

## Example 6: Mutating cached values

As mentioned in the [overview](#caching) section, the Streamlit cache stores items by reference. This allows the Streamlit cache to support structures that aren't memory-managed by Python, such as TensorFlow objects. However, it can also lead to unexpected behavior — which is why Streamlit has a few checks to guide developers in the right direction. Let's look into those checks now.
As mentioned in the [overview](#optimize-performance-with-stcache) section, the Streamlit cache stores items by reference. This allows the Streamlit cache to support structures that aren't memory-managed by Python, such as TensorFlow objects. However, it can also lead to unexpected behavior — which is why Streamlit has a few checks to guide developers in the right direction. Let's look into those checks now.

Let's write an app that has a cached function which returns a mutable object, and then let's follow up by mutating that object:

Expand Down Expand Up @@ -277,19 +277,19 @@ No surprises here. But now notice what happens when you rerun you app (i.e. pres

- Result: {output: "result was manually mutated"}
- Mutated result: {output: "result was manually mutated"}
- <Warning> Cached object mutated. (...)
- Cached object mutated. (...)

So what's up?

What's going on here is that Streamlit caches the output `res` by reference. When you mutated `res["output"]` outside the cached function you ended up inadvertently modifying the cache. This means every subsequent call to `expensive_computation(2, 21)` will return the wrong value!

Since this behavior is usually not what you'd expect, Streamlit tries to be helpful and show you a warning, along with some ideas about how to fix your code.

In this specific case, the fix is just to not mutate `res["output"]` outside the cached function. There was no good reason for us to do that anyway! Another solution would be to clone the result value with `res = deepcopy(expensive_computation(2, 21))`. Check out the section entitled [Fixing caching issues](troubleshooting/caching_issues.md) for more information on these approaches and more.
In this specific case, the fix is just to not mutate `res["output"]` outside the cached function. There was no good reason for us to do that anyway! Another solution would be to clone the result value with `res = deepcopy(expensive_computation(2, 21))`. Check out the section entitled [Fixing caching issues](/kb/troubleshooting/caching-issues) for more information on these approaches and more.

## Advanced caching

In [caching](caching.md), you learned about the Streamlit cache, which is accessed with the [`@st.cache`](api.html#streamlit.cache) decorator. In this article you'll see how Streamlit's caching functionality is implemented, so that you can use it to improve the performance of your Streamlit apps.
In [caching](/library/advanced-features/caching), you learned about the Streamlit cache, which is accessed with the [`@st.cache`](/library/api-reference/performance#stcache) decorator. In this article you'll see how Streamlit's caching functionality is implemented, so that you can use it to improve the performance of your Streamlit apps.

The cache is a key-value store, where the key is a hash of:

Expand All @@ -303,9 +303,9 @@ And the value is a tuple of:
- The cached output
- A hash of the cached output (you'll see why soon)

For both the key and the output hash, Streamlit uses a specialized hash function that knows how to traverse code, hash special objects, and can have its [behavior customized by the user](#the-hash-funcs-parameter).
For both the key and the output hash, Streamlit uses a specialized hash function that knows how to traverse code, hash special objects, and can have its [behavior customized by the user](#the-hash_funcs-parameter).

For example, when the function `expensive_computation(a, b)`, decorated with [`@st.cache`](api.html#streamlit.cache), is executed with `a=2` and `b=21`, Streamlit does the following:
For example, when the function `expensive_computation(a, b)`, decorated with [`@st.cache`](/library/api-reference/performance#stcache), is executed with `a=2` and `b=21`, Streamlit does the following:

1. Computes the cache key
1. If the key is found in the cache, then:
Expand All @@ -318,9 +318,9 @@ For example, when the function `expensive_computation(a, b)`, decorated with [`@
- Stores `key → (output, output_hash)` in the cache.
1. Returns the output.

If an error is encountered an exception is raised. If the error occurs while hashing either the key or the output an `UnhashableTypeError` error is thrown. If you run into any issues, see [fixing caching issues](troubleshooting/caching_issues.md).
If an error is encountered an exception is raised. If the error occurs while hashing either the key or the output an `UnhashableTypeError` error is thrown. If you run into any issues, see [fixing caching issues](/kb/troubleshooting/caching-issues).

### The `hash_funcs` parameter
### The hash_funcs parameter

As described above, Streamlit's caching functionality relies on hashing to calculate the key for cached objects, and to detect unexpected mutations in the cached result.

Expand All @@ -339,7 +339,7 @@ def func(file_reference):

By default, Streamlit hashes custom classes like `FileReference` by recursively navigating their structure. In this case, its hash is the hash of the filename property. As long as the file name doesn't change, the hash will remain constant.

However, what if you wanted to have the hasher check for changes to the file's modification time, not just its name? This is possible with [`@st.cache`](api.html#streamlit.cache)'s `hash_funcs` parameter:
However, what if you wanted to have the hasher check for changes to the file's modification time, not just its name? This is possible with [`@st.cache`](/library/api-reference/performance#stcache)'s `hash_funcs` parameter:

```python
class FileReference:
Expand Down Expand Up @@ -391,12 +391,12 @@ Python's [`id`](https://docs.python.org/3/library/functions.html#id) function |
- Speed: Fast
- Use case: If you want to turn off hashing of this type. This is useful if you know the object is not going to change.

Python's [`hash()`](https://docs.python.org/3/library/functions.html#hash) function | [Example](#example-3-use-python-s-hash-function)
Python's [`hash()`](https://docs.python.org/3/library/functions.html#hash) function | [Example](#example-3-use-pythons-hash-function)

- Speed: Can be slow based the size of the object being cached
- Use case: If Python already knows how to hash this type correctly.

Custom hash function | [Example](#the-hash-funcs-parameter)
Custom hash function | [Example](#the-hash_funcs-parameter)

- Speed: N/a
- Use case: If you'd like to override how Streamlit hashes a particular type.
Expand Down Expand Up @@ -444,7 +444,7 @@ def func(huge_constant_dataframe):

When Streamlit encounters an object of this type, it always converts the object into `None`, no matter which instance of `FooType` its looking at. This means all instances are hash to the same value, which effectively cancels out the hashing mechanism.

### Example 3: Use Python's `hash()` function
### Example 3: Use Python's hash() function

Sometimes, you might want to use Python’s default hashing instead of Streamlit's. For example, maybe you've encountered a type that Streamlit is unable to hash, but it's hashable with Python's built-in `hash()` function:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Configuration
slug: /reference-guides/configuration
slug: /library/advanced-features/configuration
---

# Streamlit configuration
Expand Down Expand Up @@ -50,7 +50,7 @@ streamlit cache clear
```

Clears persisted files from the on-disk [Streamlit
cache](api.html#optimize-performance), if present.
cache](/library/api-reference/performance), if present.

## Set configuration options

Expand Down Expand Up @@ -90,7 +90,7 @@ Shows all config options available for Streamlit, including their current
values:

```toml
# last updated 2021-05-13
# last updated 2021-07-22

[global]

Expand All @@ -103,6 +103,12 @@ disableWatchdogWarning = false
# Default: true
showWarningOnDirectExecution = true

# DataFrame serialization.
# Acceptable values:
# - 'legacy': Serialize DataFrames using Streamlit's custom format. Slow but battle-tested.
# - 'arrow': Serialize DataFrames using Apache Arrow. Much faster and versatile.
# Default: 'arrow'
dataFrameSerialization = "arrow"

[logger]

Expand All @@ -114,7 +120,6 @@ level = "debug"
# Default: None
messageFormat = "%(asctime)s %(levelname) -7s %(name)s: %(message)s"


[client]

# Whether to enable st.cache.
Expand All @@ -130,7 +135,6 @@ displayEnabled = true
# Default: true
showErrorDetails = true


[runner]

# Allows you to type a variable or string by itself in a single line of Python code to write it to the app.
Expand All @@ -149,7 +153,6 @@ fixMatplotlib = true
# Default: true
postScriptGC = true


[server]

# List of folders that should not be watched for changes. This impacts both "Run on Save" and @st.cache.
Expand Down Expand Up @@ -205,7 +208,6 @@ maxUploadSize = 200
# Default: true
enableWebsocketCompression = true


[browser]

# Internet address where users should point their browsers in order to connect to the app. Can be IP address or DNS name and path.
Expand All @@ -222,14 +224,12 @@ gatherUsageStats = true
# Default: whatever value is set in server.port.
serverPort = 8501


[mapbox]

# Configure Streamlit to use a custom Mapbox token for elements like st.pydeck_chart and st.map. To get a token for yourself, create an account at https://mapbox.com. It's free (for moderate usage levels)!
# Default: ""
token = ""


[deprecation]

# Set to false to disable the deprecation warning for the file uploader encoding.
Expand All @@ -249,7 +249,6 @@ showImageFormat = "True"
# Default: "True"
showPyplotGlobalUse = "True"


[s3]

# Name of the AWS S3 bucket to save apps.
Expand Down Expand Up @@ -284,7 +283,6 @@ keyPrefix = ""
# Default: (unset)
#profile =


[theme]

# Primary accent color for interactive elements.
Expand Down
Loading