Is there a way to dynamically change the color of input sliders globally?
I am familiar with using chooseSliderSkin from the shinyWidgets package to modify CSS and change colors. However, I am facing an issue where this only works in the UI section and not on the server side where it needs to access the input value for the desired color change.
When I execute the code below, the "Flat" skin is not applied correctly, resulting in unusual slider bar colors (though the labels display the right color). Additionally, the change only occurs once.
library(shinydashboard)
library(shiny)
library(shinyWidgets)
ui <- dashboardPage(
dashboardHeader(
title = "Title"),
dashboardSidebar(
radioGroupButtons(
inputId = "switch",
choices = c("Red"="true", "Blue"="false"),
justified=TRUE
),
sliderInput("abc", "abc", 0, 1, .5, .1),
sliderInput("def", "def", 0, 1, .5, .1)
),
dashboardBody(
uiOutput("slidercols")
)
)
server <- function(input, output) {
output$slidercols <- renderUI({
chooseSliderSkin(skin="Flat", ifelse(input$switch=="true", "red", "blue"))
})
}
shinyApp(ui, server)
This is how chooseSliderSkin typically functions (non-reactive):
library(shinydashboard)
library(shiny)
library(shinyWidgets)
ui <- dashboardPage(
dashboardHeader(
title = "Title"),
dashboardSidebar(
radioGroupButtons(
inputId = "switch",
choices = c("Red"="true", "Blue"="false"),
justified=TRUE
),
sliderInput("abc", "abc", 0, 1, .5, .1),
sliderInput("def", "def", 0, 1, .5, .1)
),
dashboardBody(
chooseSliderSkin(skin="Flat", "red")
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
I am seeking a method to generalize this solution for other similar CSS-altering functions meant for the UI section.