A faster way to build and share data apps
Core display functions for rendering text, data, and content in various formats. These functions form the foundation of Streamlit's content display capabilities.
The universal display function that automatically formats and renders various data types.
def write(*args, unsafe_allow_html=False, **kwargs):
"""
Write arguments to the app using the most appropriate format.
Parameters:
- *args: Variable length argument list of content to display
- unsafe_allow_html (bool): Allow HTML content rendering (default: False)
- **kwargs: Additional keyword arguments
Returns:
None
"""Display formatted text using Markdown syntax with optional HTML support.
def markdown(body, unsafe_allow_html=False, help=None):
"""
Display string formatted as Markdown.
Parameters:
- body (str): The Markdown string to display
- unsafe_allow_html (bool): Allow HTML tags in markdown (default: False)
- help (str): Optional tooltip that appears on hover
Returns:
None
"""
def text(body):
"""
Write fixed-width and preformatted text.
Parameters:
- body (str): The text to display
Returns:
None
"""
def latex(body):
"""
Display mathematical expressions formatted as LaTeX.
Parameters:
- body (str): The LaTeX string to render
Returns:
None
"""Display content with semantic heading levels and caption styling.
def title(body, anchor=None, help=None):
"""
Display text in title formatting.
Parameters:
- body (str): The text to display as title
- anchor (str): Optional HTML anchor for the title
- help (str): Optional tooltip
Returns:
None
"""
def header(body, anchor=None, help=None, divider=None):
"""
Display text in header formatting.
Parameters:
- body (str): The text to display as header
- anchor (str): Optional HTML anchor
- help (str): Optional tooltip
- divider (str or bool): Add divider line ('rainbow', True, or False)
Returns:
None
"""
def subheader(body, anchor=None, help=None, divider=None):
"""
Display text in subheader formatting.
Parameters:
- body (str): The text to display as subheader
- anchor (str): Optional HTML anchor
- help (str): Optional tooltip
- divider (str or bool): Add divider line ('rainbow', True, or False)
Returns:
None
"""
def caption(body, unsafe_allow_html=False, help=None):
"""
Display text in small font as a caption.
Parameters:
- body (str): The caption text
- unsafe_allow_html (bool): Allow HTML rendering
- help (str): Optional tooltip
Returns:
None
"""Display code blocks, JSON data, and HTML content with proper formatting.
def code(body, language=None, line_numbers=False):
"""
Display a code block with syntax highlighting.
Parameters:
- body (str): The code string to display
- language (str): Programming language for syntax highlighting
- line_numbers (bool): Show line numbers (default: False)
Returns:
None
"""
def json(body):
"""
Display object or string as pretty-printed JSON.
Parameters:
- body: Object to display as JSON (dict, list, string, etc.)
Returns:
None
"""
def html(body, width=None, height=None, scrolling=False):
"""
Display HTML content in an iframe.
Parameters:
- body (str): HTML content to render
- width (int): Width in pixels
- height (int): Height in pixels (default: 150)
- scrolling (bool): Enable scrolling in iframe
Returns:
None
"""Display content from iterables and generators in real-time.
def write_stream(stream):
"""
Display content from a generator or iterable as it's produced.
Parameters:
- stream: Generator or iterable yielding content to display
Returns:
Generator yielding displayed content
"""Additional content display utilities for help and documentation.
def help(obj):
"""
Display the help string for an object.
Parameters:
- obj: Python object to display help for
Returns:
None
"""import streamlit as st
# Various text formats
st.title("My Application")
st.header("Section Header")
st.subheader("Subsection")
st.text("Plain text content")
st.caption("Small caption text")
# Markdown formatting
st.markdown("""
## Markdown Section
- **Bold text**
- *Italic text*
- `Code snippet`
- [Link](https://streamlit.io)
""")# Display Python code with syntax highlighting
st.code('''
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
''', language='python', line_numbers=True)
# Display JSON data
data = {"name": "Alice", "age": 30, "city": "NYC"}
st.json(data)
# Mathematical expressions
st.latex(r'\sum_{i=1}^{n} x_i = x_1 + x_2 + \ldots + x_n')import pandas as pd
import matplotlib.pyplot as plt
# write() automatically chooses the best display format
st.write("Hello, World!") # Text
st.write(42) # Number
st.write({"key": "value"}) # Dictionary as JSON
st.write(pd.DataFrame({"A": [1, 2], "B": [3, 4]})) # DataFrame as table
# Display matplotlib figure
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4])
st.write(fig) # Matplotlib figureInstall with Tessl CLI
npx tessl i tessl/pypi-streamlit@1.49.0