with st.expander('About this app'): st.write('This app shows the various ways on how you can layout your Streamlit app.') st.image('https://streamlit.io/images/brand/streamlit-logo-secondary-colormark-darktext.png', width=250)
st.sidebar.header('Input') user_name = st.sidebar.text_input('What is your name?') user_emoji = st.sidebar.selectbox('Choose an emoji', ['', '😄', '😆', '😊', '😍', '😴', '😕', '😱']) user_food = st.sidebar.selectbox('What is your favorite food?', ['', 'Tom Yum Kung', 'Burrito', 'Lasagna', 'Hamburger', 'Pizza'])
st.header('Output')
col1, col2, col3 = st.columns(3)
with col1: if user_name != '': st.write(f'👋 Hello {user_name}!') else: st.write('👈 Please enter your **name**!')
with col2: if user_emoji != '': st.write(f'{user_emoji} is your favorite **emoji**!') else: st.write('👈 Please choose an **emoji**!')
with col3: if user_food != '': st.write(f'🍴 **{user_food}** is your favorite **food**!') else: st.write('👈 Please choose your favorite **food**!')
with st.expander("See explanation"): st.write(\"\"\" The chart above shows some numbers I picked for you. I rolled actual dice for these, so they're *guaranteed* to be random. \"\"\") st.image("https://static.streamlit.io/examples/dice.jpg")
运行效果:
示例2:
1 2 3 4 5 6 7 8 9 10 11
import streamlit as st
st.bar_chart({"data": [1, 5, 2, 6, 2, 1]})
expander = st.expander("See explanation") expander.write(\"\"\" The chart above shows some numbers I picked for you. I rolled actual dice for these, so they're *guaranteed* to be random. \"\"\") expander.image("https://static.streamlit.io/examples/dice.jpg")