This time, we’ll build a "Student Performance Dashboard" that allows users to upload student data, filter by grades, visualize the results, and download reports.
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# App Title
st.title("Student Performance Dashboard")
# Sidebar for Input
st.sidebar.header("Student Data Filters")
# Text Input for a Teacher's Name
teacher_name = st.sidebar.text_input("Enter your name (Teacher):")
# File uploader to upload student data
uploaded_file = st.sidebar.file_uploader("Upload a CSV with student data", type=["csv"])
# Sidebar Slider to filter grades
min_grade = st.sidebar.slider("Minimum Grade Filter", 0, 100, 50)
# Sidebar Dropdown for Grade Level Selection
grade_level = st.sidebar.selectbox("Select Grade Level", options=['All', 'Freshman', 'Sophomore', 'Junior', 'Senior'])
# Button to confirm report generation
generate_report = st.sidebar.button("Generate Performance Report")
# Display simple welcome message using st.text()
st.text(f"Hello {teacher_name}, please upload the student data and apply filters!")
# Markdown for Instructions
st.markdown("""
### Instructions:
1. Upload a CSV file containing student data (Name, Grade, Class, and Performance).
2. Apply the filters to see how the student performance changes.
3. Generate a report by clicking the button in the sidebar.
""")
# If file is uploaded, process the data
if uploaded_file is not None:
data = pd.read_csv(uploaded_file)
# Filter data by grade and level
if grade_level != 'All':
data = data[data['Grade_Level'] == grade_level]
filtered_data = data[data['Grade'] >= min_grade]
# Display filtered data
st.subheader("Filtered Student Data")
st.dataframe(filtered_data)
# Static Table View
st.subheader("Static Table of Student Data")
st.table(filtered_data.head())
# Line Chart - Grade progression over time
st.subheader("Line Chart of Grades Over Time")
st.line_chart(filtered_data.set_index('Student_Name')['Grade'])
# Bar Chart - Distribution of Grades
st.subheader("Bar Chart of Grade Distribution")
st.bar_chart(filtered_data['Grade'].value_counts())
# Area Chart - Grade Trends
st.subheader("Area Chart of Performance")
st.area_chart(filtered_data.set_index('Student_Name')['Performance'])
# Display Summary using st.write()
st.subheader("Summary Statistics")
st.write(filtered_data.describe())
# If button is clicked, display a success message
if generate_report:
st.success("Performance report generated successfully!")
# Code block to show the process
st.code('''
# Sample Code for processing student data
import pandas as pd
df = pd.read_csv('student_data.csv')
filtered_data = df[df['Grade'] > 50]
print(filtered_data)
''')
# Display an image (dummy school logo) and play an audio file
st.subheader("School Logo and Anthem")
st.image("https://placekitten.com/300/200", caption="School Logo")
st.audio("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3")
else:
# If no file is uploaded, show a default message
st.warning("Please upload a CSV file to get started.")
# Footer text
st.text("Thank you for using the Student Performance Dashboard.")
st.write()
– Displays summaries and statistics of the student data.st.title()
– Displays the app’s title.st.header()
– Adds headers to different sections.st.subheader()
– Adds smaller section headers (used for charts and filtered data).st.text()
– Simple text to welcome the teacher and provide a footer.st.markdown()
– Displays Markdown-formatted text to provide instructions.st.code()
– Displays a block of formatted code as an example for the user.st.dataframe()
– Displays an interactive table for the filtered student data.st.table()
– Displays a static table with student data.st.line_chart()
– Line chart showing student grades over time.st.bar_chart()
– Bar chart for grade distribution.st.area_chart()
– Area chart to show performance trends.st.selectbox()
– Dropdown for selecting grade levels.st.slider()
– Slider widget to filter student grades.st.text_input()
– Text input box to capture the teacher’s name.st.file_uploader()
– File uploader for uploading student data in CSV format.st.button()
– Button to trigger report generation.st.sidebar()
– Adds a sidebar for filtering and user inputs.st.image()
– Displays a school logo (or any image).st.audio()
– Plays an audio file (school anthem or any audio).This example demonstrates how to combine interactive filters, data visualizations, and media elements in a more practical dashboard-like scenario.