0

This is how my shiny app looks like: enter image description here

The blue slider looks bad with the red navbar. Does anyone know how to change it to red? I'm using shinytheme("united").

LyzandeR
  • 37,047
  • 12
  • 77
  • 87
W W
  • 769
  • 1
  • 11
  • 26

2 Answers2

4

This is similar to @LyzandeR answer, but uses simpler code and doesn't use any additional packages

library(shiny)

mycss <- "
.irs-bar,
.irs-bar-edge,
.irs-single,
.irs-grid-pol {
  background: red;
  border-color: red;
}
"

ui <- fluidPage(
  tags$style(mycss),
  sliderInput("num", "Number", 0, 10, 5)
)

server <- function(input, output, session) {}

shinyApp(ui, server)
DeanAttali
  • 25,268
  • 10
  • 92
  • 118
  • doesn't work as expected when you want to style 2 sliderInputs differently though.... still trying to find a working solution for it that actually targets them by a tag. Adding #num (slider's ID) before the CSS doesn't work, and tried also to put the sliders in a div(id = 'slider1' , etc and then put #slider1 in front of the css code, not working as i'd hope. – Mark Nov 06 '18 at 14:36
1

It is not the easiest task, but it can happen. All you need to do is change the CSS of the default bootstrap theme that shiny uses by default. I will use tableHTML (allows you add a CSS file to shiny from the ui) to show you which CSS to change:

library(tableHTML)
ui <- fluidPage(
 tags$style(make_css(list('.irs-bar', 
                          c('border-top', 'border-bottom', 'background'), 
                          rep('red', 3)),
                     list('.irs-bar-edge',
                          c('background', 'border'),
                          c('red', '0px !important')),
                     list('.irs-single',
                          'background',
                          'red'))),
 sliderInput("obs", "Number of observations:",
             min = 0, max = 1000, value = 500
 ),
 plotOutput("distPlot")
)

# Server logic
server <- function(input, output) {
 output$distPlot <- renderPlot({
  hist(rnorm(input$obs))
 })
}

# Complete app with UI and server components
shinyApp(ui, server)
}

As you can see above (in the make_css function) you need to change .irs-bar, .irs-bar-edge and .irs-single and add whichever colour you want. I used the standard red. You can find a tutorial on tableHTML::make_css here if you want to find out more.

enter image description here

LyzandeR
  • 37,047
  • 12
  • 77
  • 87
  • 1
    is there a reason to add the complexity of introducing an additional package and function (and tutorial)? Can't OP do the same by just adding this CSS the good old fashioned way into the app? – DeanAttali Nov 05 '17 at 07:33