I have this minimal example adapted from here R shiny radiogroup Button change color:
library(shiny)
ui = fluidPage(
radioGroupButtons(
# status = "primary ", ## you can change status value to change to select few colors
inputId = "a",
checkIcon = list(yes = icon("check")),
choiceValues = 0:3,
choiceNames = paste0(0:3),
justified = TRUE, width = "300px"
),
tags$script("$(\"input:radio[name='a'][value=0]\").parent().css('background-color', '#7EF373');"),
tags$script("$(\"input:radio[name='a'][value=1]\").parent().css('background-color', '#E7E7E7');"),
tags$script("$(\"input:radio[name='a'][value=2]\").parent().css('background-color', '#EDB6B2');"),
tags$script("$(\"input:radio[name='a'][value=3]\").parent().css('background-color', '#DE6B63');"),
radioGroupButtons(
# status = "primary ", ## you can change status value to change to select few colors
inputId = "b",
checkIcon = list(yes = icon("check")),
choiceValues = 0:3,
choiceNames = paste0(0:3),
justified = TRUE, width = "300px"
),
tags$script("$(\"input:radio[name='b'][value=0]\").parent().css('background-color', '#7EF373');"),
tags$script("$(\"input:radio[name='b'][value=1]\").parent().css('background-color', '#E7E7E7');"),
tags$script("$(\"input:radio[name='b'][value=2]\").parent().css('background-color', '#EDB6B2');"),
tags$script("$(\"input:radio[name='b'][value=3]\").parent().css('background-color', '#DE6B63');")
)
server = function(...) {}
shinyApp(ui, server)
It basically colors the grouped radio buttons.
I would like to apply this colors to each radioGroupButtons Widget without using the four rows again and again.
I tried doing it with a css file in the parent directory but I don't know how to write the four rows in css e.g.
How to write:
tags$script("$(\"input:radio[name='a'][value=0]\").parent().css('background-color', '#7EF373');"),
tags$script("$(\"input:radio[name='a'][value=1]\").parent().css('background-color', '#E7E7E7');"),
tags$script("$(\"input:radio[name='a'][value=2]\").parent().css('background-color', '#EDB6B2');"),
tags$script("$(\"input:radio[name='a'][value=3]\").parent().css('background-color', '#DE6B63');"),
in the .css file and use it in the radioGroupButtons widget?