- Spec files
pypi-streamlit
Describes: pkg:pypi/streamlit@1.49.x
- Description
- A faster way to build and share data apps
- Author
- tessl
- Last updated
display-content.md docs/
1# Display and Content23Core display functions for rendering text, data, and content in various formats. These functions form the foundation of Streamlit's content display capabilities.45## Capabilities67### Multi-purpose Display89The universal display function that automatically formats and renders various data types.1011```python { .api }12def write(*args, unsafe_allow_html=False, **kwargs):13"""14Write arguments to the app using the most appropriate format.1516Parameters:17- *args: Variable length argument list of content to display18- unsafe_allow_html (bool): Allow HTML content rendering (default: False)19- **kwargs: Additional keyword arguments2021Returns:22None23"""24```2526### Markdown and Rich Text2728Display formatted text using Markdown syntax with optional HTML support.2930```python { .api }31def markdown(body, unsafe_allow_html=False, help=None):32"""33Display string formatted as Markdown.3435Parameters:36- body (str): The Markdown string to display37- unsafe_allow_html (bool): Allow HTML tags in markdown (default: False)38- help (str): Optional tooltip that appears on hover3940Returns:41None42"""4344def text(body):45"""46Write fixed-width and preformatted text.4748Parameters:49- body (str): The text to display5051Returns:52None53"""5455def latex(body):56"""57Display mathematical expressions formatted as LaTeX.5859Parameters:60- body (str): The LaTeX string to render6162Returns:63None64"""65```6667### Typography and Headers6869Display content with semantic heading levels and caption styling.7071```python { .api }72def title(body, anchor=None, help=None):73"""74Display text in title formatting.7576Parameters:77- body (str): The text to display as title78- anchor (str): Optional HTML anchor for the title79- help (str): Optional tooltip8081Returns:82None83"""8485def header(body, anchor=None, help=None, divider=None):86"""87Display text in header formatting.8889Parameters:90- body (str): The text to display as header91- anchor (str): Optional HTML anchor92- help (str): Optional tooltip93- divider (str or bool): Add divider line ('rainbow', True, or False)9495Returns:96None97"""9899def subheader(body, anchor=None, help=None, divider=None):100"""101Display text in subheader formatting.102103Parameters:104- body (str): The text to display as subheader105- anchor (str): Optional HTML anchor106- help (str): Optional tooltip107- divider (str or bool): Add divider line ('rainbow', True, or False)108109Returns:110None111"""112113def caption(body, unsafe_allow_html=False, help=None):114"""115Display text in small font as a caption.116117Parameters:118- body (str): The caption text119- unsafe_allow_html (bool): Allow HTML rendering120- help (str): Optional tooltip121122Returns:123None124"""125```126127### Code and Technical Content128129Display code blocks, JSON data, and HTML content with proper formatting.130131```python { .api }132def code(body, language=None, line_numbers=False):133"""134Display a code block with syntax highlighting.135136Parameters:137- body (str): The code string to display138- language (str): Programming language for syntax highlighting139- line_numbers (bool): Show line numbers (default: False)140141Returns:142None143"""144145def json(body):146"""147Display object or string as pretty-printed JSON.148149Parameters:150- body: Object to display as JSON (dict, list, string, etc.)151152Returns:153None154"""155156def html(body, width=None, height=None, scrolling=False):157"""158Display HTML content in an iframe.159160Parameters:161- body (str): HTML content to render162- width (int): Width in pixels163- height (int): Height in pixels (default: 150)164- scrolling (bool): Enable scrolling in iframe165166Returns:167None168"""169```170171### Content Streaming172173Display content from iterables and generators in real-time.174175```python { .api }176def write_stream(stream):177"""178Display content from a generator or iterable as it's produced.179180Parameters:181- stream: Generator or iterable yielding content to display182183Returns:184Generator yielding displayed content185"""186```187188### Utility Functions189190Additional content display utilities for help and documentation.191192```python { .api }193def help(obj):194"""195Display the help string for an object.196197Parameters:198- obj: Python object to display help for199200Returns:201None202"""203```204205## Usage Examples206207### Basic Text Display208209```python210import streamlit as st211212# Various text formats213st.title("My Application")214st.header("Section Header")215st.subheader("Subsection")216st.text("Plain text content")217st.caption("Small caption text")218219# Markdown formatting220st.markdown("""221## Markdown Section222- **Bold text**223- *Italic text*224- `Code snippet`225- [Link](https://streamlit.io)226""")227```228229### Code and Technical Content230231```python232# Display Python code with syntax highlighting233st.code('''234def fibonacci(n):235if n <= 1:236return n237return fibonacci(n-1) + fibonacci(n-2)238''', language='python', line_numbers=True)239240# Display JSON data241data = {"name": "Alice", "age": 30, "city": "NYC"}242st.json(data)243244# Mathematical expressions245st.latex(r'\sum_{i=1}^{n} x_i = x_1 + x_2 + \ldots + x_n')246```247248### Dynamic Content with write()249250```python251import pandas as pd252import matplotlib.pyplot as plt253254# write() automatically chooses the best display format255st.write("Hello, World!") # Text256st.write(42) # Number257st.write({"key": "value"}) # Dictionary as JSON258st.write(pd.DataFrame({"A": [1, 2], "B": [3, 4]})) # DataFrame as table259260# Display matplotlib figure261fig, ax = plt.subplots()262ax.plot([1, 2, 3, 4])263st.write(fig) # Matplotlib figure264```