Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add different static colors for sliderbar in shiny dashboard

I am new to shiny. I would like to give static color for the slider bar irrespective of the range selected in shiny dashboard. I want to have different color for slider as follows, Ex: 0 to 40 – red, 40 to 60 – blue, 60 to 100 – green. Please help me solve this issue. My code,

library(shiny)
library(shinydashboard)

ui <- dashboardPage(skin = "black",
                    dashboardHeader(title = "test"),

                  dashboardSidebar(
                    sidebarMenu(
                      menuItem("Complete", tabName = "comp"))),

                    dashboardBody(
                      tabItems(
                        tabItem(tabName = "comp",
                          fluidRow(
                              sliderInput("range_var", "", value = c(90,100), min = 0, max = 100, width = '200%'))))))

server <- function(input, output, session) { 
  observe({
    updateSliderInput(session, "range_var", label = "", value = c(90, 100), min = 0, max = 100)
  })
}
shinyApp(ui, server)

Thanks Balaji

like image 356
Balaji N Avatar asked May 16 '18 05:05

Balaji N


1 Answers

Oh, then i misinterpreted your question. You can achieve this also by using css-commands and correct selectors:

library(shiny)
library(shinydashboard)
library(shinyjs)

ui <- dashboardPage(skin = "black",
                    dashboardHeader(title = "test"),
                    dashboardSidebar(
                      sidebarMenu(
                        menuItem("Complete", tabName = "comp"))),
                    dashboardBody(
                      inlineCSS(".irs-line-left { background-color: red; width: 40%;}
                                 .irs-line-mid { background-color: blue; width: 20%; left: 40%;}
                                 .irs-line-right { background-color: green; width: 40%; left: 60%;}
                                "
                                ),

                      shinyjs::useShinyjs(),
                      tabItems(
                        tabItem(tabName = "comp",
                                fluidRow(
                                  sliderInput("range_var", "", value = c(90,100), min = 0, max = 100, width = '200%'))))))

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

shinyApp(ui, server)
like image 190
SeGa Avatar answered Sep 27 '22 00:09

SeGa