I'm writing a shinny app, and I'm trying to change the color of the options displayed in a selectInput based on conditions. My intention is that if the option's name is "Installed", to paint it green, and if it's not, red I've tried with shinyjs::addClass() but failed.
This is what I got so far:
library(shiny)
library(shinyjs)
names <- c("A", "B", "C")
installed <- c("TRUE", "FALSE", "FALSE")
options <- data.frame(names, installed)
ui <- fluidPage(
useShinyjs(),
# inlineCSS("#someId .selectize-dropdown-content > .option { color: red; }"),
# inlineCSS("#someId .selectize-input { color: red; }"),
inlineCSS(".red {color:red;}"),
inlineCSS(".green {color: green;}"),
selectInput("apkgs", "Select a package", choices = options$names),
)
server <- function(input, output, session) {
observe({
if(input$apkgs %in% installed) {
addClass(selector="input.apkgs", class="green")
} else {
addClass(selector="input.apkgs", class="red")
}
})
}
shinyApp(ui, server)