pypi-streamlit

Description
A faster way to build and share data apps
Author
tessl
Last updated

How to use

npx @tessl/cli registry install tessl/pypi-streamlit@1.49.0

display-content.md docs/

1
# Display and Content
2
3
Core display functions for rendering text, data, and content in various formats. These functions form the foundation of Streamlit's content display capabilities.
4
5
## Capabilities
6
7
### Multi-purpose Display
8
9
The universal display function that automatically formats and renders various data types.
10
11
```python { .api }
12
def write(*args, unsafe_allow_html=False, **kwargs):
13
"""
14
Write arguments to the app using the most appropriate format.
15
16
Parameters:
17
- *args: Variable length argument list of content to display
18
- unsafe_allow_html (bool): Allow HTML content rendering (default: False)
19
- **kwargs: Additional keyword arguments
20
21
Returns:
22
None
23
"""
24
```
25
26
### Markdown and Rich Text
27
28
Display formatted text using Markdown syntax with optional HTML support.
29
30
```python { .api }
31
def markdown(body, unsafe_allow_html=False, help=None):
32
"""
33
Display string formatted as Markdown.
34
35
Parameters:
36
- body (str): The Markdown string to display
37
- unsafe_allow_html (bool): Allow HTML tags in markdown (default: False)
38
- help (str): Optional tooltip that appears on hover
39
40
Returns:
41
None
42
"""
43
44
def text(body):
45
"""
46
Write fixed-width and preformatted text.
47
48
Parameters:
49
- body (str): The text to display
50
51
Returns:
52
None
53
"""
54
55
def latex(body):
56
"""
57
Display mathematical expressions formatted as LaTeX.
58
59
Parameters:
60
- body (str): The LaTeX string to render
61
62
Returns:
63
None
64
"""
65
```
66
67
### Typography and Headers
68
69
Display content with semantic heading levels and caption styling.
70
71
```python { .api }
72
def title(body, anchor=None, help=None):
73
"""
74
Display text in title formatting.
75
76
Parameters:
77
- body (str): The text to display as title
78
- anchor (str): Optional HTML anchor for the title
79
- help (str): Optional tooltip
80
81
Returns:
82
None
83
"""
84
85
def header(body, anchor=None, help=None, divider=None):
86
"""
87
Display text in header formatting.
88
89
Parameters:
90
- body (str): The text to display as header
91
- anchor (str): Optional HTML anchor
92
- help (str): Optional tooltip
93
- divider (str or bool): Add divider line ('rainbow', True, or False)
94
95
Returns:
96
None
97
"""
98
99
def subheader(body, anchor=None, help=None, divider=None):
100
"""
101
Display text in subheader formatting.
102
103
Parameters:
104
- body (str): The text to display as subheader
105
- anchor (str): Optional HTML anchor
106
- help (str): Optional tooltip
107
- divider (str or bool): Add divider line ('rainbow', True, or False)
108
109
Returns:
110
None
111
"""
112
113
def caption(body, unsafe_allow_html=False, help=None):
114
"""
115
Display text in small font as a caption.
116
117
Parameters:
118
- body (str): The caption text
119
- unsafe_allow_html (bool): Allow HTML rendering
120
- help (str): Optional tooltip
121
122
Returns:
123
None
124
"""
125
```
126
127
### Code and Technical Content
128
129
Display code blocks, JSON data, and HTML content with proper formatting.
130
131
```python { .api }
132
def code(body, language=None, line_numbers=False):
133
"""
134
Display a code block with syntax highlighting.
135
136
Parameters:
137
- body (str): The code string to display
138
- language (str): Programming language for syntax highlighting
139
- line_numbers (bool): Show line numbers (default: False)
140
141
Returns:
142
None
143
"""
144
145
def json(body):
146
"""
147
Display object or string as pretty-printed JSON.
148
149
Parameters:
150
- body: Object to display as JSON (dict, list, string, etc.)
151
152
Returns:
153
None
154
"""
155
156
def html(body, width=None, height=None, scrolling=False):
157
"""
158
Display HTML content in an iframe.
159
160
Parameters:
161
- body (str): HTML content to render
162
- width (int): Width in pixels
163
- height (int): Height in pixels (default: 150)
164
- scrolling (bool): Enable scrolling in iframe
165
166
Returns:
167
None
168
"""
169
```
170
171
### Content Streaming
172
173
Display content from iterables and generators in real-time.
174
175
```python { .api }
176
def write_stream(stream):
177
"""
178
Display content from a generator or iterable as it's produced.
179
180
Parameters:
181
- stream: Generator or iterable yielding content to display
182
183
Returns:
184
Generator yielding displayed content
185
"""
186
```
187
188
### Utility Functions
189
190
Additional content display utilities for help and documentation.
191
192
```python { .api }
193
def help(obj):
194
"""
195
Display the help string for an object.
196
197
Parameters:
198
- obj: Python object to display help for
199
200
Returns:
201
None
202
"""
203
```
204
205
## Usage Examples
206
207
### Basic Text Display
208
209
```python
210
import streamlit as st
211
212
# Various text formats
213
st.title("My Application")
214
st.header("Section Header")
215
st.subheader("Subsection")
216
st.text("Plain text content")
217
st.caption("Small caption text")
218
219
# Markdown formatting
220
st.markdown("""
221
## Markdown Section
222
- **Bold text**
223
- *Italic text*
224
- `Code snippet`
225
- [Link](https://streamlit.io)
226
""")
227
```
228
229
### Code and Technical Content
230
231
```python
232
# Display Python code with syntax highlighting
233
st.code('''
234
def fibonacci(n):
235
if n <= 1:
236
return n
237
return fibonacci(n-1) + fibonacci(n-2)
238
''', language='python', line_numbers=True)
239
240
# Display JSON data
241
data = {"name": "Alice", "age": 30, "city": "NYC"}
242
st.json(data)
243
244
# Mathematical expressions
245
st.latex(r'\sum_{i=1}^{n} x_i = x_1 + x_2 + \ldots + x_n')
246
```
247
248
### Dynamic Content with write()
249
250
```python
251
import pandas as pd
252
import matplotlib.pyplot as plt
253
254
# write() automatically chooses the best display format
255
st.write("Hello, World!") # Text
256
st.write(42) # Number
257
st.write({"key": "value"}) # Dictionary as JSON
258
st.write(pd.DataFrame({"A": [1, 2], "B": [3, 4]})) # DataFrame as table
259
260
# Display matplotlib figure
261
fig, ax = plt.subplots()
262
ax.plot([1, 2, 3, 4])
263
st.write(fig) # Matplotlib figure
264
```