library(shiny) library(ggplot2) library(dplyr) # Load your dataset # data <- read.csv("path_to_your_dataset.csv") ui <- fluidPage( titlePanel("HR Management Analytics Dashboard"), sidebarLayout( sidebarPanel( selectInput("department", "Select Department:", choices = unique(data$Department)), selectInput("time_period", "Select Time Period:", choices = c("Last Month", "Last Quarter", "Last Year")) ), mainPanel( tabsetPanel( tabPanel("Overview", fluidRow( valueBoxOutput("total_employees"), valueBoxOutput("avg_salary"), valueBoxOutput("avg_age") ), fluidRow( valueBoxOutput("gender_distribution"), valueBoxOutput("marital_status_distribution"), valueBoxOutput("job_level_distribution") ), plotOutput("age_distribution"), plotOutput("experience_distribution") ), tabPanel("Performance", plotOutput("performance_by_department"), plotOutput("performance_by_age"), plotOutput("performance_by_experience") ), tabPanel("Engagement", plotOutput("engagement_by_gender"), plotOutput("engagement_by_marital_status"), plotOutput("engagement_by_job_level") ), tabPanel("Attrition", plotOutput("attrition_by_age"), plotOutput("attrition_by_department"), plotOutput("attrition_by_experience") ) ) ) ) ) server <- function(input, output) { filtered_data <- reactive({ data %>% filter(Department == input$department) }) output$total_employees <- renderValueBox({ valueBox( nrow(filtered_data()), "Total Employees", icon = icon("users"), color = "blue" ) }) output$avg_salary <- renderValueBox({ avg_salary <- round(mean(filtered_data()$Salary), 2) valueBox( avg_salary, "Avg Salary", icon = icon("dollar-sign"), color = "green" ) }) output$avg_age <- renderValueBox({ avg_age <- round(mean(filtered_data()$Age), 2) valueBox( avg_age, "Avg Age", icon = icon("calendar"), color = "purple" ) }) output$gender_distribution <- renderPlot({ ggplot(filtered_data(), aes(x = "", fill = Gender)) + geom_bar(width = 1) + coord_polar(theta = "y") + labs(title = "Gender Distribution", x = "", y = "") + scale_fill_manual(values = c("Male" = "blue", "Female" = "pink")) + theme_void() + geom_text(aes(label = paste0(round((..count..)/sum(..count..)*100), "%")), stat = "count", position = position_stack(vjust = 0.5)) }) output$marital_status_distribution <- renderPlot({ ggplot(filtered_data(), aes(x = MaritalStatus, fill = MaritalStatus)) + geom_bar() + labs(title = "Marital Status Distribution", x = "Marital Status", y = "Count") + scale_fill_manual(values = c("Single" = "red", "Married" = "green", "Divorced" = "orange")) }) output$job_level_distribution <- renderPlot({ ggplot(filtered_data(), aes(x = JobLevel, fill = JobLevel)) + geom_bar() + labs(title = "Job Level Distribution", x = "Job Level", y = "Count") }) output$age_distribution <- renderPlot({ ggplot(filtered_data(), aes(x = Age)) + geom_histogram(binwidth = 1, fill = "blue", color = "black") + labs(title = "Age Distribution", x = "Age", y = "Count") }) output$experience_distribution <- renderPlot({ ggplot(filtered_data(), aes(x = TotalWorkingYears)) + geom_histogram(binwidth = 1, fill = "green", color = "black") + labs(title = "Total Working Years Distribution", x = "Total Working Years", y = "Count") }) output$performance_by_department <- renderPlot({ ggplot(filtered_data(), aes(x = Department, y = PerformanceRating, fill = Department)) + geom_boxplot() + labs(title = "Performance by Department", x = "Department", y = "Performance Rating") }) output$performance_by_age <- renderPlot({ ggplot(filtered_data(), aes(x = Age, y = PerformanceRating)) + geom_point(color = "blue") + labs(title = "Performance by Age", x = "Age", y = "Performance Rating") }) output$performance_by_experience <- renderPlot({ ggplot(filtered_data(), aes(x = TotalWorkingYears, y = PerformanceRating)) + geom_point(color = "green") + labs(title = "Performance by Experience", x = "Total Working Years", y = "Performance Rating") }) output$engagement_by_gender <- renderPlot({ ggplot(filtered_data(), aes(x = Gender, y = JobInvolvement, fill = Gender)) + geom_boxplot() + labs(title = "Engagement by Gender", x = "Gender", y = "Engagement Score") }) output$engagement_by_marital_status <- renderPlot({ ggplot(filtered_data(), aes(x = MaritalStatus, y = JobInvolvement, fill = MaritalStatus)) + geom_boxplot() + labs(title = "Engagement by Marital Status", x = "Marital Status", y = "Engagement Score") }) output$engagement_by_job_level <- renderPlot({ ggplot(filtered_data(), aes(x = JobLevel, y = JobInvolvement, fill = JobLevel)) + geom_boxplot() + labs(title = "Engagement by Job Level", x = "Job Level", y = "Engagement Score") }) output$attrition_by_age <- renderPlot({ ggplot(filtered_data(), aes(x = Age, y = Attrition, fill = Attrition)) + geom_bar(stat = "identity") + labs(title = "Attrition by Age", x = "Age", y = "Attrition") }) output$attrition_by_department <- renderPlot({ ggplot(filtered_data(), aes(x = Department, y = Attrition, fill = Department)) + geom_bar(stat = "identity") + labs(title = "Attrition by Department", x = "Department", y = "Attrition") }) output$attrition_by_experience <- renderPlot({ ggplot(filtered_data(), aes(x = TotalWorkingYears, y = Attrition, fill = Attrition)) + geom_bar(stat = "identity") + labs(title = "Attrition by Total Working Years", x = "Total Working Years", y = "Attrition") }) } shinyApp(ui, server)