Customization
Streamlit provides several configuration options to customize the behavior and appearance of your app.
Configuration Options
All available configuration options are found here in the official docs. You can also view all available configuration options using this command:
streamlit config showStreamlit provide 4 different ways to set configuration options. The list is given below in the order of precedence:
- Command line flags
- Environment variables
- Project-specific config file
- Global config file
NOTE
The order of precedence will come into play when the same configuration option is provided at multiple places. For example, command line flags take precedence over environment variables when the same configuration option is provided at both of them.
Command line flags
You can pass the configuration as command line flags as shown below:
streamlit run your_script.py --server.port 80NOTE
When using command line flags, the section header should be separated with a period (ex: server.port), but the same case of variable should be used (ex: server.enableStaticServing).
Environment variables
You can also set environment variables using upper snake-cased words and a STREAMLIT_ prefix. The above example can be set using environment variables as follows:
export STREAMLIT_SERVER_PORT=80NOTE
Similarly, when using environment variables, the section header along with the variable should be converted to snake case with a STREAMLIT_ prefix (ex: STREAMLIT_SERVER_ENABLE_STATIC_SERVING).
Project-specific config file
Similar to secrets, you can also configure options using the project-specific config file at $ROOT/.streamlit/config.toml ($ROOT is the folder you're running Streamlit from).
<!-- Inside the project-specific config.toml -->
[server]
port = 80Global config file
You can also use the global config file, found at:
~/.streamlit/config.tomlon macOS/Linux%userprofile%/.streamlit/config.tomlon Windows
Disable Telemetry
By default, Streamlit collects usage statistics and telemetry data. If you'd like to opt out of usage statistics, add the following to your config file:
[browser]
gatherUsageStats = falseTheming
Streamlit themes are defined using regular config options: a theme can be set via command line flag when starting your app using streamlit run or by defining it in the [theme] section of a .streamlit/config.toml file.
The following config options show the default Streamlit Light theme recreated in the [theme] section of a .streamlit/config.toml file:
[theme]
<!-- Accent color -->
primaryColor="#FF4B4B"
<!-- Main content background color -->
backgroundColor="#FFFFFF"
<!-- Second background color for contrast, ex: sidebar -->
secondaryBackgroundColor="#F0F2F6"
<!-- Text color of the app -->
textColor="#31333F"
<!-- Font for the app, accepted values are: "sans serif", "serif", and "monospace" -->
font="sans serif"TIP
You can use any CSS color for above options. That is, the theme colors can be specified in hex or RGB or HSL or with browser-supported color names like "green", "yellow", and "chartreuse"
NOTE
The code blocks are always rendered using the monospace font regardless of the font selected in config file.
base option
If you want to make small changes to one of the preset Streamlit themes, you can use base option. With this option, your custom theme can inherit from a preset Streamlit theme and then you can define only the ones you want to override in a config file.
The base option accepts either light or dark as values and defaults to light when omitted. The following example shows the config for a custom theme which is nearly identical to the Streamlit Dark theme, but with a new primaryColor:
[theme]
base="dark"
primaryColor="purple"Static file serving
Streamlit apps can host and serve small, static media files to support media embedding use cases within the Streamlit media elements.
To enable this feature, set enableStaticServing = true under [server] in your config file, or environment variable STREAMLIT_SERVER_ENABLE_STATIC_SERVING=true.
Media stored in the folder ./static/ relative to the running app file is served at path app/static/[filename], such as http://localhost:8501/app/static/cat.png.
<!-- Inside .streamlit/config.toml -->
[server]
enableStaticServing = true# app.py
import streamlit as st
with st.echo():
st.title("CAT")
st.markdown("[](https://streamlit.io)")Usage details
- Files with the following extensions will be served normally:
".jpg", ".jpeg", ".png", ".gif". Any other file will be sent with headerContent-Type:text/plainwhich will cause browsers to render in plain text. This is included for security - other file types that need to render should be hosted outside the app. - Streamlit also sets
X-Content-Type-Options:nosnifffor all files rendered from the static directory. - For apps running on Streamlit Community Cloud:
- Files available in the Github repo will always be served. Any files generated while the app is running, such as based on user interaction (file upload, etc), are not guaranteed to persist across user sessions.
- Apps which store and serve many files, or large files, may run into resource limits and be shut down.
