Hi, I am new to Shiny and have issues embedding my existing code into Shiny and make it responsive.
The intent of the code is to calculate by what factor salaries need to be increased to reduce a gender pay gap: Therefore, data is split based on the CompaRatio value defined in the code (value from 0-100). Then, TTC (salaries) of the dataset with low CompaRatio is increased by the increase factor initially defined. Based on this input, the "new" gender pay gaps are calculated using the Oaxaca package and the costs of the increase:
CompaThres <- 90
Increase <- 1.05
equity <- subset(data, data$Mean_CR < CompaThres & data$Gender_num == 1)
equity_inv <- subset(data, data$Gender_num == 0 | (data$Mean_CR >= CompaThres & data$Gender_num == 1))
equity$TTC_new <- equity$TTC * Increase
equity_inv$TTC_new <- equity_inv$TTC
Costs <- sum(equity$TTC_new - equity$TTC)
Equity_all <- rbind(equity, equity_inv)
Oaxaca_TTC_new <- oaxaca(formula = TTC_new ~ Personal_Pos_Grade.r + Achievement+ Age + ADM + BCPM + CO + CS + FI + GM + HR + IT + IR + LE + MK + OPS + OE + PR + RE + SA + WAF | Gender_oa , data = Equity_all, R = 1)
I would like to visualize this in Shiny with the user defining if salaries 1) from men, women, or all should be increased 2) below which CompaRatio value and 3) by what increase factor. The result should then display the new gender pay gap, costs of the increase and a graph in the main panel.
My question would be where I need to insert the code to make it work in Shiny and make it responsive. So far, I have the entire code before the Shiny part but Shiny cannot seem to work with objects defined prior. Thanks a lot in advance!
library(shiny)
# Define UI ----
ui <- fluidPage(
titlePanel("Pay Equity Calculator"),
sidebarLayout(
sidebarPanel(
helpText("Choose your options"),
checkboxGroupInput("checkGroup",
h3(strong("Scope")),
choices = list("Female" = 1,
"Male" = 0),
selected = 1),
sliderInput("range",
label = h3(strong("CompaRatio Threshold")),
min = 0, max = 100, value = c(80)),
sliderInput("increase",
label = h3(strong("Increase in %")),
min = 0, max = 10, value = c(2))
),
mainPanel(
textOutput("range")
)
)
)
# Define server logic ----
server <- function(input, output) {
output$range <- renderText({
paste(input$range)
})
}
# Run the app ----
shinyApp(ui = ui, server = server)