«Столбцы Streamlit» — это функция библиотеки Python Streamlit, которая позволяет вам организовывать содержимое вашего приложения в несколько столбцов. Вот несколько методов, которые вы можете использовать для создания столбцов в Streamlit:
- Использование функции
st.columns(). Вы можете использовать функциюst.columns()для создания нескольких столбцов в приложении Streamlit. Он возвращает список объектов столбцов, которые можно использовать для отображения содержимого рядом. Вот пример:
import streamlit as st
# Create two columns
col1, col2 = st.columns(2)
# Display content in the first column
col1.header("Column 1")
col1.write("This is the content of column 1.")
# Display content in the second column
col2.header("Column 2")
col2.write("This is the content of column 2.")
- Использование оператора
with. Вы также можете использовать операторwithдля создания столбцов в Streamlit. Вот пример:
import streamlit as st
# Use the 'with' statement to create columns
with st.container():
# Content in the first column
st.header("Column 1")
st.write("This is the content of column 1.")
with st.container():
# Content in the second column
st.header("Column 2")
st.write("This is the content of column 2.")
- Использование пользовательского CSS: Streamlit позволяет применять к вашему приложению собственные стили CSS. Вы можете использовать сетку CSS или другие методы макетирования для создания столбцов. Вот пример:
import streamlit as st
# Apply custom CSS to create columns
st.markdown(
"""
<style>
.columns {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
}
</style>
""",
unsafe_allow_html=True
)
# Create columns using the custom CSS class
st.markdown('<div class="columns">', unsafe_allow_html=True)
with st.container():
# Content in the first column
st.header("Column 1")
st.write("This is the content of column 1.")
with st.container():
# Content in the second column
st.header("Column 2")
st.write("This is the content of column 2.")
# Close the columns div
st.markdown('</div>', unsafe_allow_html=True)