selectInput: does it automatically removes options' leading spaces?


In here, I deliberately set names(male) = " male" and names(female) = " female" to indent and differentiate them from "sex"; however, this does not work once shiny runs. Is there a way that I can fix this?

For a reproducible example, see below where 'Male' and 'Female' should be displayed with indents.


  shinyApp(
    ui = fluidPage(
      selectInput("state", "Choose a state:",
                  list(`categorical` = c("Sex"= "Sex", "  Male" = "Male", "  Female" = "Female"))
      ),
      textOutput("result")
    ),
    server = function(input, output) {
      output$result <- renderText({
        paste("You chose", input$state)
      })
    }
  )

I am slightly confused as to what you are trying to accomplish. Is 'Sex' supposed to be the grouping title? Or is the user able to select any of the three? If they are supposed to be different, hence the indenting, then maybe it is worth moving them into a separate selectInput

1 Like

Thanks for your suggestions! The example is just a mini one and my intention is to allow user to select one variable to create dummy variable and stuff. The user can select a whole group, i.e. "Sex" and also its sub-category, i.e. Male or Female. And the reason I scramble them together is to make the whole selection process compact, because there are also other elements floating on the panel.