Streamlit-workshop

5. User Input Widgets

st.button() - Creates a clickable button.

if st.button("Click Me"):
    st.write("Button clicked!")

st.text_input() - Takes text input from the user.

name = st.text_input("Enter your name:")
st.write("Hello", name)

st.number_input() - Takes numeric input (int/float).

age = st.number_input("Enter your age:", min_value=1, max_value=100)
st.write("You are", age, "years old.")

st.text_area() - Multi-line text input.

feedback = st.text_area("Write your feedback:")

st.date_input() - Takes a date input.

date = st.date_input("Select your Date ")
st.write("Date:", date)

st.time_input() - Takes time input.

time = st.time_input("Select time")

st.slider() - Creates a slider for numeric range.

level = st.slider("Select difficulty level", 0, 10, 5)
st.write("Level:", level)

st.selectbox() - Dropdown menu (single selection).

option = st.selectbox("Choose your language", ["Python", "C++", "Java"])
st.write("You selected:", option)

st.multiselect() - Dropdown menu (multiple selections).

skills = st.multiselect("Select your skills", ["Python", "JS", "C++"])
st.write("You chose:", skills)

st.checkbox() - Checkbox for boolean input.

agree = st.checkbox("I agree to terms and conditions")
if agree:
    st.success("Thank you!")

st.radio() - Select one option from a list (radio buttons).

gender = st.radio("Select gender:", ["Male", "Female", "Other"])
st.write("Gender:", gender)

st.file_uploader() - Allows uploading of files.

file = st.file_uploader("Upload a CSV file", type=["csv"])
if file:
    import pandas as pd
    df = pd.read_csv(file)
    st.dataframe(df)

Home || Previous || Next . . .