Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background color of selectInput in R Shiny

Tags:

css

r

shiny

My example code:

library(shiny)

server <- function(input, output) {
}

ui <- fluidPage(
  br(),
  selectInput("select1", "Choose: ", c("Alt1.1", "Alt1.2"), selected = c("Alt1.1"), selectize = FALSE, multiple = TRUE),
  br(),
  selectInput("select2", "Choose: ", c("Alt2.1", "Alt2.2"), selected = c("Alt2.1"), selectize = FALSE, multiple = TRUE)
)

shinyApp(ui = ui, server = server)

How do I have to change the code so that the background color of the widgets is red for select1 and blue for select2?

EDIT:

I tried this:

div(selectInput("select1", "Choose: ", c("Alt1.1", "Alt1.2"), selected = c("Alt1.1"), selectize = FALSE, multiple = TRUE), style = "background-color: red")

enter image description here

But this is not what I am looking for! Instead I want the background of the options to be red!

like image 547
Felix Grossmann Avatar asked Jul 28 '17 13:07

Felix Grossmann


1 Answers

Edited as requested in the comments below

You can add CSS through style tags as follows:

library(shiny)

server <- function(input, output) {
}

ui <- fluidPage(
  br(),
  tags$style("#select1 {border: 2px solid #dd4b39;}"),
  selectInput("select1", "Choose: ", c("Alt1.1", "Alt1.2"), selected = c("Alt1.1"), selectize = FALSE, multiple = TRUE),
  br(),
  tags$style("#select2 {background-color:blue;}"),
  selectInput("select2", "Choose: ", c("Alt2.1", "Alt2.2"), selected = c("Alt2.1"), selectize = FALSE, multiple = TRUE)
)

shinyApp(ui = ui, server = server)

enter image description here

like image 98
Florian Avatar answered Nov 14 '22 22:11

Florian