checkboxGroupInput with sidebar menu item in R shiny

I am trying to add a checkbox in R shiny where I get values dynamically from another dataframe. So in this case for gender we are showing Male and Female. Below is the code on how its happening.

UI.r

 sidebarMenu(menuItem(
  "Population Filters", startExpanded = TRUE,
  uiOutput("choose_ethnicity"),
  uiOutput("choose_age"),
  checkboxGroupInput('features', 'features',  uiOutput("choose_gender"),selected = TRUE),
  checkboxInput('features', 'Total')
))

Server.r

 output$choose_gender <- renderUI({observe({
        checkboxGroupInput("features", "Select features to plot: ", choices= levels(with_demo_vars()$gender), selected = levels(with_demo_vars()$gender))

  })
  })

What I want to do in Shiny is add another level. This way you can see another checkbox Total and when the user clicks on Total it should select male and female and when you uncheck Total it should uncheck the checkboxes below it. How can this be done.

how to add checkboxgroup values if i select multi choices