I'm trying to render several sliders based on user's number input. This works pretty nice, however, I'm not able to change the colour of the newly rendered sliders.
See example:
if (interactive()) {
ui <- fluidPage(
tags$style(HTML(".js-irs-0 .irs-single, .js-irs-0 .irs-bar-edge, .js-irs-0 .irs-bar
{background: red}"),
HTML(".js-irs-1 .irs-single, .js-irs-1 .irs-bar-edge, .js-irs-1 .irs-bar
{background: blue}"),
HTML(".js-irs-2 .irs-single, .js-irs-2 .irs-bar-edge, .js-irs-2 .irs-bar
{background: green}"),
HTML(".js-irs-3 .irs-single, .js-irs-3 .irs-bar-edge, .js-irs-3 .irs-bar
{background: yellow}"),
HTML(".js-irs-4 .irs-single, .js-irs-4 .irs-bar-edge, .js-irs-4 .irs-bar
{background: purple}")),
numericInput("num", "Number", value = 1, min = 1, max = 5),
uiOutput("rendersliders")
)
# Server logic
server <- function(input, output) {
output$rendersliders <- renderUI({
num <- input$num
sliders <- tagList(
sliderInput("slider1", "Slider 1",
value = 1, min = 1, max = 5, step = 1),
sliderInput("slider2", "Slider 2",
value = 2, min = 1, max = 5, step = 1),
sliderInput("slider3", "Slider 3",
value = 3, min = 1, max = 5, step = 1),
sliderInput("slider4", "Slider 4",
value = 4, min = 1, max = 5, step = 1),
sliderInput("slider5", "Slider 5",
value = 5, min = 1, max = 5, step = 1)
)
sliders <- sliders[1:num]
sliders
})
}
# Complete app with UI and server components
shinyApp(ui, server)
}
When I change number of sliders, this stops working. I guess this is because new sliders are rendered and the first slider (initially rendered) is no longer visible.
Moreover, this wont work properly, when there are some other sliders before and after these ones rendered.
Is there any way how to render sliders with their own style?