import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
# Generate data
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Plotting
fig, ax = plt.subplots()
ax.plot(x, y)
st.pyplot(fig)
import streamlit as st
import pandas as pd
# File uploader
uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
# Display file contents
if uploaded_file is not None:
data = pd.read_csv(uploaded_file)
st.write(data)
import streamlit as st
import pandas as pd
# Load data
data = pd.read_csv("data.csv")
# Selectbox for filtering
selected_category = st.selectbox("Select category", data["Category"].unique())
# Filter data
filtered_data = data[data["Category"] == selected_category]
# Display filtered data
st.write(filtered_data)
import streamlit as st
# Button widget
if st.button("Click me"):
st.write("Button clicked!")
import streamlit as st
# Sidebar navigation
page = st.sidebar.selectbox("Select a page", ["Home", "About", "Contact"])
# Display different content based on page selection
if page == "Home":
st.write("Welcome to the Home page.")
elif page == "About":
st.write("This is the About page.")
else:
st.write("Contact us at contact@example.com")
import streamlit as st
import plotly.graph_objects as go
# Create a Plotly figure
fig = go.Figure(data=go.Bar(x=[1, 2, 3], y=[4, 1, 2]))
# Display the plot
st.plotly_chart(fig)
import streamlit as st
import time
# Displaying a progress bar
progress_bar = st.progress(0)
for i in range(100):
time.sleep(0.1)
progress_bar.progress(i + 1)
import streamlit as st
# Applying custom CSS
st.markdown("""
<style>
.custom-text {
color: red;
font-size: 24px;
}
</style>
""", unsafe_allow_html=True)
# Displaying text with custom style
st.write('<div class="custom-text">Custom text</div>', unsafe_allow_html=True)
import streamlit as st
# Error handling
try:
# Code that may raise an error
result = 1 / 0
st.write("Result:", result)
except Exception as e:
st.error(f"An error occurred: {e}")
import streamlit as st
import pandas as pd
# Downloadable data link
download_link = st.sidebar.button("Download Data")
# Generate and display data
data = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
st.write(data)
# Create a download link
if download_link:
csv = data.to_csv(index=False)
st.download_button(label="Download CSV", data=csv, file_name="data.csv", mime="text/csv")
import streamlit as st
# Markdown and HTML content
st.markdown("## Markdown Heading")
st.write('<div style="color: blue;">HTML content</div>', unsafe_allow_html=True)
# Example of Streamlit app code (app.py)
import streamlit as st
def main():
st.title("My Streamlit App")
st.write("Hello, Streamlit!")
if __name__ == "__main__":
main()