πΒ Β Echo Expander
Submitted by Brian Hess
Summary
Execute code, and show the code that was executed, but in an expander.
Functions
echo_expander
Execute code, and show the code that was executed, but in an expander.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_location |
str
|
Whether to show the echoed code above or below. Defaults to "above". |
'above'
|
expander |
bool
|
Whether the code block should occur in an expander. Defaults to True. |
True
|
label |
str
|
If expander is True, then the label for the expander. Defaults to "Show code". |
'Show code'
|
Source code in src/streamlit_extras/echo_expander/__init__.py
Import:
- You should add this to the top of your .py file
Examples
example1
def example1():
with echo_expander():
import streamlit as st
st.markdown(
"""
This component is a combination of `st.echo` and `st.expander`.
The code inside the `with echo_expander()` block will be executed,
and the code can be shown/hidden behind an expander
"""
)
Output (beta)
example2
def example2():
with echo_expander(code_location="below", label="Simple Dataframe example"):
import pandas as pd
import streamlit as st
df = pd.DataFrame(
[[1, 2, 3, 4, 5], [11, 12, 13, 14, 15]],
columns=("A", "B", "C", "D", "E"),
)
st.dataframe(df)