- Spec files
pypi-streamlit
Describes: pkg:pypi/streamlit@1.16.x
- Description
- The fastest way to build and share data apps
- Author
- tessl
- Last updated
display-elements.md docs/
1# Display Elements and Text23Core functions for displaying text, data, and status messages. These elements form the foundation of Streamlit's content display capabilities, providing everything from basic text formatting to sophisticated data visualization.45## Capabilities67### Text and Headers89Display formatted text content with various emphasis levels and styling options.1011```python { .api }12def title(body: str, anchor: str = None) -> DeltaGenerator:13"""14Display text in title formatting as the largest header.1516Parameters:17- body: The text to display as title18- anchor: Optional anchor name for the title19"""2021def header(body: str, anchor: str = None) -> DeltaGenerator:22"""23Display text in header formatting (H1 level).2425Parameters:26- body: The text to display as header27- anchor: Optional anchor name for the header28"""2930def subheader(body: str, anchor: str = None) -> DeltaGenerator:31"""32Display text in subheader formatting (H2 level).3334Parameters:35- body: The text to display as subheader36- anchor: Optional anchor name for the subheader37"""3839def text(body: str) -> DeltaGenerator:40"""41Display plain text.4243Parameters:44- body: The text to display45"""4647def caption(body: str, unsafe_allow_html: bool = False) -> DeltaGenerator:48"""49Display text in small, muted formatting for captions.5051Parameters:52- body: The text to display as caption53- unsafe_allow_html: Whether to allow HTML tags (use with caution)54"""55```5657#### Usage Example5859```python60import streamlit as st6162st.title("My Application")63st.header("Data Analysis")64st.subheader("Results Summary")65st.text("This is regular text content.")66st.caption("This is a caption with smaller, muted text.")67```6869### Markdown and Code7071Display rich formatted content including Markdown, LaTeX, and syntax-highlighted code.7273```python { .api }74def markdown(body: str, unsafe_allow_html: bool = False) -> DeltaGenerator:75"""76Display Markdown-formatted text.7778Parameters:79- body: The Markdown text to display80- unsafe_allow_html: Whether to allow HTML tags (use with caution)81"""8283def latex(body: str) -> DeltaGenerator:84"""85Display LaTeX-formatted mathematical expressions.8687Parameters:88- body: The LaTeX expression to render89"""9091def code(body: str, language: str = "python") -> DeltaGenerator:92"""93Display code with syntax highlighting.9495Parameters:96- body: The code string to display97- language: Programming language for syntax highlighting98"""99```100101#### Usage Example102103```python104import streamlit as st105106# Markdown content107st.markdown("""108## My Report109This is **bold** and this is *italic*.110""")111112# LaTeX expression113st.latex(r"\sum_{i=1}^{n} x_i^2")114115# Code with syntax highlighting116st.code("""117def hello_world():118print("Hello, Streamlit!")119""", language="python")120```121122### Data Display123124Present structured data in tables and interactive dataframes.125126```python { .api }127def dataframe(data, width: int = None, height: int = None, use_container_width: bool = False) -> DeltaGenerator:128"""129Display an interactive dataframe.130131Parameters:132- data: pandas.DataFrame, dict, list, or array-like data133- width: Width in pixels (None for auto-sizing)134- height: Height in pixels (None for auto-sizing)135- use_container_width: Whether to use full container width136"""137138def table(data) -> DeltaGenerator:139"""140Display a static table.141142Parameters:143- data: pandas.DataFrame, dict, list, or array-like data144"""145146def json(body) -> DeltaGenerator:147"""148Display JSON data in an expandable tree format.149150Parameters:151- body: JSON-serializable object to display152"""153```154155#### Usage Example156157```python158import streamlit as st159import pandas as pd160161# Sample data162data = pd.DataFrame({163'Name': ['Alice', 'Bob', 'Charlie'],164'Age': [25, 30, 35],165'City': ['New York', 'London', 'Tokyo']166})167168# Interactive dataframe169st.dataframe(data)170171# Static table172st.table(data)173174# JSON display175st.json({176"users": ["alice", "bob"],177"settings": {"theme": "dark", "notifications": True}178})179```180181### Metrics and Key Values182183Display key performance indicators and metrics with optional delta indicators.184185```python { .api }186def metric(label: str, value, delta=None, delta_color: str = "normal") -> DeltaGenerator:187"""188Display a metric with an optional delta indicator.189190Parameters:191- label: The metric label/name192- value: The current metric value193- delta: Optional change indicator (number or string)194- delta_color: Color for delta ("normal", "inverse", or "off")195"""196```197198#### Usage Example199200```python201import streamlit as st202203# Metrics with deltas204col1, col2, col3 = st.columns(3)205206with col1:207st.metric("Revenue", "$1.2M", "+12.5%")208209with col2:210st.metric("Users", "1,234", "+56")211212with col3:213st.metric("Conversion", "3.4%", "-0.2%", delta_color="inverse")214```215216### Status Messages and Alerts217218Communicate application status, information, warnings, and errors to users.219220```python { .api }221def success(body: str) -> DeltaGenerator:222"""223Display a success message with green styling.224225Parameters:226- body: The success message text227"""228229def info(body: str) -> DeltaGenerator:230"""231Display an informational message with blue styling.232233Parameters:234- body: The information message text235"""236237def warning(body: str) -> DeltaGenerator:238"""239Display a warning message with yellow styling.240241Parameters:242- body: The warning message text243"""244245def error(body: str) -> DeltaGenerator:246"""247Display an error message with red styling.248249Parameters:250- body: The error message text251"""252253def exception(exception: Exception) -> DeltaGenerator:254"""255Display an exception with full traceback.256257Parameters:258- exception: The Exception object to display259"""260```261262#### Usage Example263264```python265import streamlit as st266267# Status messages268st.success("Operation completed successfully!")269st.info("Here's some helpful information.")270st.warning("This action cannot be undone.")271st.error("An error occurred during processing.")272273# Exception display274try:275result = 1 / 0276except ZeroDivisionError as e:277st.exception(e)278```279280### Magic Write Function281282Universal display function that intelligently renders different data types.283284```python { .api }285def write(*args, **kwargs) -> DeltaGenerator:286"""287Magic function that displays almost anything.288289Parameters:290- *args: Variable arguments of various types to display291- **kwargs: Keyword arguments passed to specific display functions292293Supported types:294- str: Displays as markdown295- pandas.DataFrame: Displays as interactive dataframe296- dict/list: Displays as JSON297- matplotlib.pyplot.Figure: Displays as chart298- PIL.Image: Displays as image299- And many more...300"""301```302303#### Usage Example304305```python306import streamlit as st307import pandas as pd308import matplotlib.pyplot as plt309310# Write can display many different types311st.write("Hello **world**!") # Markdown312st.write({"key": "value"}) # JSON313st.write(pd.DataFrame({"A": [1, 2], "B": [3, 4]})) # DataFrame314315# Multiple arguments316st.write("The answer is", 42, "!")317```318319### Help and Documentation320321Display help information and documentation for Python objects.322323```python { .api }324def help(obj) -> DeltaGenerator:325"""326Display help documentation for a Python object.327328Parameters:329- obj: Any Python object to display help for330"""331```332333#### Usage Example334335```python336import streamlit as st337import pandas as pd338339# Display help for a function340st.help(pd.DataFrame)341342# Display help for built-in functions343st.help(len)344```