Reputation: 421
I have a Shiny Dashabord with multiple selectInputs. Now I want to change the background color of the selectInput if a value outside of the default was clicked.
So here is a code snippet:
dbHeader <- dashboardHeader(
title = "Test",
titleWidth = "400px"
)
ui <- dashboardPage(
dbHeader,
dashboardSidebar(
uiOutput("filter_head")
),
dashboardBody(
#some content
)
)
server <- function(input, output, session) {
output$filter_head <- renderUI({
column(
12,
selectInput("select_1", h3("Select1"),
c(
"Default", "A", "B",
"C",
"D"
), selected = "Default", selectize = FALSE, multiple = F)
),
selectInput("select_2", h3("Select2"),
c(
"Default", "A", "B",
"C",
"D"
), selected = "Default", selectize = FALSE, multiple = F)
)
)
})
}
shinyApp(ui, server)
So if not default was selected at select_1, the background of select_1 should be red otherwise white. But only for the select_1 Input. Is this possible?
Upvotes: 0
Views: 319
Reputation: 421
Ok I got it. With an uiOutput and an if else statement.
I create a new uiOutput Element and uses the statement in the render Method:
uiOutput("style_select_1")
output$style_select_1<- renderUI({
if(is.null(input$select_1)){
return()
}
else if(input$select_1!= 'Default'){
return(tags$style("#select_1{background-color:red;color:white;}"))
}
})
Upvotes: 2