Streamlit Functions and Keywords for Data
Science and Machine Learning
Streamlit is a powerful open-source Python framework for building interactive web applications
easily. This guide covers essential functions and keywords frequently used in creating data-driven
and machine learning web apps.
1. Basic Setup
1 import streamlit as st
2 [Link]('Title Text')
3 [Link]('Header Text')
4 [Link]('Subheader Text')
5 [Link]('Simple text display')
6 [Link]('**Markdown support**')
7 [Link]('Flexible text or data display')
2. Widgets (User Input)
1 [Link]('Click Me')
2 [Link]('Check this')
3 [Link]('Pick one:', ['Option 1', 'Option 2'])
4 [Link]('Choose:', ['A', 'B', 'C'])
5 [Link]('Pick multiple:', ['A', 'B', 'C'])
6 [Link]('Select range', 0, 100, 50)
7 st.text_input('Enter text')
8 st.number_input('Enter number')
9 st.date_input('Pick a date')
10 st.file_uploader('Upload a file')
3. Displaying Data
1 [Link](df)
2 [Link](df)
3 [Link]({'key':'value'})
4 [Link](label='Accuracy', value='95%', delta='+3%')
4. Charts and Visualizations
1 st.line_chart(data)
2 st.bar_chart(data)
3 st.area_chart(data)
4 [Link](fig)
5 [Link](df)
5. Layout and Design
1 [Link]('Sidebar Title')
2 [Link]('Click')
3 col1, col2 = [Link](2)
4 with [Link]('See more'):
6. Media
1 [Link]('[Link]', caption='Sample Image')
2 [Link]('audio.mp3')
3 [Link]('video.mp4')
7. Control Flow
1 [Link](50)
2 [Link]('Loading...')
3 [Link]()
4 [Link]()
8. Caching and Optimization
1 @st.cache_data
2 def load_data(): return df
3 @st.cache_resource
4 def load_model(): return model
9. Machine Learning Integration
1 model = [Link]('[Link]')
2 prediction = [Link](input_data)
3 [Link]('Prediction:', prediction)
10. Deployment Tips
1 Save file as [Link]
2 Run with: streamlit run [Link]
3 Deploy via Streamlit Cloud or other platforms