In my R Shiny app, I am looking to color elements based on their index number (first element blue, second yellow, third red).
Here is a reproducible example:
library(shiny)
ui <- fluidPage(
tags$style(".control-label:nth-of-type(1) {background-color:blue;}"),
tags$style(".control-label:nth-of-type(2) {background-color:yellow;}"),
tags$style(".control-label:nth-of-type(3) {background-color:red;}"),
lapply(
letters[1:3],
FUN = function(name){
selectizeInput(
inputId = paste0("type_", name),
label = paste0(name),
choices = "a",
selected = "a",
multiple = TRUE,
options = list(create = TRUE)
)
}
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
This is what I have tried so far:
Based on: Stack Overflow CSS Selector for First Element I explored some options:
- Trying to use the (~) Operator for overwriting with the first match, but unsure how to do it efficiently for the subsequent elements.
- Experimenting with
:nth-of-type(1)
, facing difficulties in implementation as seen in the example above.