change colour of selectizeInput options in R Shiny

后端 未结 2 1782
栀梦
栀梦 2020-12-21 11:14

I would like to change the colour of each individual option of the selectizeInput menu in my Shiny app. In the following example code below I am able to change

相关标签:
2条回答
  • 2020-12-21 11:52

    Replacing my code with the above suggested code changed the drop down menu colour but NOT the individual items in the menu:

    
    shinyApp(
      ui = 
        shinyUI(fluidPage(
          tags$head(
            tags$style(HTML("
            .option[data-value=a] {
              background: red !important;
              color: white !important;
            }
            .option[data-value=b] {
              background: green !important;
              color: white !important;
            }
      "))
          ),
          sidebarLayout(
            sidebarPanel(
              selectizeInput("select", label=NULL,
                             choices=c("a", "b"),
                             selected = c("a", "b"),
                             multiple=TRUE, options=list(placeholder="Wybierz"))),
            mainPanel())
        )
        ),
      server = function(input, output){}
    )
    

    SOLUTION In order to achieve both items colour coded and the drop down. I needed to add .item to my code

    
    shinyApp(
      ui = 
        shinyUI(fluidPage(
          tags$head(
            tags$style(HTML("
            .option[data-value=a], .item[data-value=a]{
              background: red !important;
              color: white !important;
            }
            .option[data-value=b], .item[data-value=b]{
              background: green !important;
              color: white !important;
            }
      "))
          ),
          sidebarLayout(
            sidebarPanel(
              selectizeInput("select", label=NULL,
                             choices=c("a", "b"),
                             selected = c("a", "b"),
                             multiple=TRUE, options=list(placeholder="Wybierz"))),
            mainPanel())
        )
        ),
      server = function(input, output){}
    )
    

    This results in both the menu and drop down menu being coloured.

    0 讨论(0)
  • 2020-12-21 12:09

    You can do:

    .option[data-value=a] {
      background: red !important;
      color: white !important;
    }
    .option[data-value=b] {
      background: green !important;
      color: white !important;
    }
    .option[data-value=c] {
      background: blue !important;
      color: white !important;
    }
    .option[data-value=d] {
      background: magenta !important;
      color: white !important;
    }
    
    0 讨论(0)
提交回复
热议问题