gender = read.csv("gender_wage_gap.csv")
head(gender)
##   data_version       indicator                      measure date_interval year
## 1    2025.9.15 Gender wage gap  Gender wage gap, raw median          year 1980
## 2    2025.9.15 Gender wage gap  Gender wage gap, raw median          year 1980
## 3    2025.9.15 Gender wage gap  Gender wage gap, raw median          year 1980
## 4    2025.9.15 Gender wage gap  Gender wage gap, raw median          year 1980
## 5    2025.9.15 Gender wage gap Gender wage gap, raw average          year 1980
## 6    2025.9.15 Gender wage gap Gender wage gap, raw average          year 1980
##   quarter month geo_type      geo_name geo_code          group group_value
## 1      NA    NA national United States        0                    Overall
## 2      NA    NA national United States        0 Race/Ethnicity       Black
## 3      NA    NA national United States        0 Race/Ethnicity       White
## 4      NA    NA national United States        0 Race/Ethnicity    Hispanic
## 5      NA    NA national United States        0                    Overall
## 6      NA    NA national United States        0 Race/Ethnicity       Black
##       value
## 1 0.3653914
## 2 0.2454772
## 3 0.3832719
## 4 0.2431395
## 5 0.3390426
## 6 0.2125375
library(shiny)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
# Load data
gender <- read.csv("gender_wage_gap.csv")

ui <- fluidPage(
  titlePanel("Gender Wage Gap Trends"),
  
  fluidRow(
    column(6, plotlyOutput("avg_plot")),
    column(6, plotlyOutput("med_plot"))
  )
)

server <- function(input, output) {
  
  # ---- Raw Average Plot ----
  output$avg_plot <- renderPlotly({
    
    avg_data <- gender %>%
      filter(measure == "Gender wage gap, raw average")
    
    p_avg <- ggplot(
      avg_data,
      aes(
        x = year,
        y = value,
        color = group_value,
        group = group_value,
        text = paste0(
          "Year: ", year,
          "<br>Race/Ethnicity: ", group_value,
          "<br>Wage gap: ", round(value * 100, 1), "%"
        )
      )
    ) +
      geom_line(linewidth = 1.6) +
      labs(
        title = "Gender Wage Gap (Raw Average)",
        x = "Year",
        y = "Wage Gap (%)",
        color = "Race/Ethnicity"
      ) +
      theme_minimal()
    
    ggplotly(p_avg, tooltip = "text")
  })
  
  # ---- Raw Median Plot ----
  output$med_plot <- renderPlotly({
    
    med_data <- gender %>%
      filter(measure == "Gender wage gap, raw median")
    
    p_med <- ggplot(
      med_data,
      aes(
        x = year,
        y = value,
        color = group_value,
        group = group_value,
        text = paste0(
          "Year: ", year,
          "<br>Race/Ethnicity: ", group_value,
          "<br>Wage gap: ", round(value * 100, 1), "%"
        )
      )
    ) +
      geom_line(linewidth = 1.6) +
      labs(
        title = "Gender Wage Gap (Raw Median)",
        x = "Year",
        y = "Wage Gap (%)",
        color = "Race/Ethnicity"
      ) +
      theme_minimal()
    
    ggplotly(p_med, tooltip = "text")
  })
}

shinyApp(ui = ui, server = server)
Shiny applications not supported in static R Markdown documents