Search code examples
rshinyshinywidgets

Change materialSwitch colors in Shiny


How can I change the colors of a materialSwitch element in a Shiny app? I know that tags$style(...) can be used inside ui.R to modify CSS styles, but I don’t know the specific class names of these kind of elements.


Solution

  • I just found out how to change the color of an active MaterialSwitch button. Just add the following to your Shiny app on your ui.R file:

    tags$style(type = "text/css", "
      .label-default {background-color: #1574D6;}
      "),
    

    In this example, the switch turns to color blue when active.