import streamlit as st import plotly.express as px import pandas as pd from services.api import fetch_data def render_dashboard(): st.sidebar.subheader("Select Analysis") analysis_option = st.sidebar.selectbox( "Choose an analysis type:", [ "Employee Satisfaction", "Department Performance", "Training Analytics", "Engagement vs Performance", "Cost-Benefit Analysis", "Training Effectiveness", "Diversity & Inclusion", "Work-Life Balance Impact", "Career Development" ] ) # API endpoint mapping endpoint_mapping = { "Employee Satisfaction": "/satisfaction-analysis", "Department Performance": "/department-performance", "Training Analytics": "/training-analytics", "Engagement vs Performance": "/engagement-performance-correlation", "Cost-Benefit Analysis": "/cost-benefit-analysis", "Training Effectiveness": "/training-effectiveness", "Diversity & Inclusion": "/diversity-dashboard", "Work-Life Balance Impact": "/worklife-balance-impact", "Career Development": "/career-development" } # Fetch data data = fetch_data(endpoint_mapping[analysis_option]) if data is None: st.error("Failed to fetch data.") return st.title(f"📊 {analysis_option}") # Correlation metric if isinstance(data, dict) and "correlation_coefficient" in data: st.metric("Correlation Coefficient", data["correlation_coefficient"]) return # Display DataFrame if isinstance(data, pd.DataFrame) and not data.empty: st.dataframe(data) # Generate visualization fig = None if analysis_option == "Employee Satisfaction": fig = px.bar(data, x="DepartmentType", y="Satisfaction Score", title="Satisfaction Score by Department", color="DepartmentType") elif analysis_option == "Department Performance": fig = px.line(data, x="DepartmentType", y=["Performance Score", "Current Employee Rating"], title="Departmental Performance Trends", markers=True) elif analysis_option == "Training Analytics": fig = px.bar(data, x="Training Program Name", y="Training Outcome", title="Training Participation by Program", color="Training Program Name") elif analysis_option == "Cost-Benefit Analysis": fig = px.scatter(data, x="DepartmentType", y="ROI", title="ROI by Department", size="ROI") elif analysis_option == "Training Effectiveness": fig = px.bar(data, x="Training Program Name", y="Performance Score", title="Training Effectiveness by Program", color="Training Program Name") elif analysis_option == "Diversity & Inclusion": fig = px.bar(data, x="Category", y="Count", color="Group", title="Diversity & Inclusion Breakdown", barmode="stack") elif analysis_option == "Career Development": fig = px.histogram(data, x="Career Movements", title="Career Progression Histogram") # Display chart if fig: st.plotly_chart(fig)