Answering your question briefly, customizing checkboxes in HTML and CSS is not a straightforward task. If you're hesitant to directly modify the code, it's advisable not to invest time in this.
In creating the checkbox container, checkBoxGroupInput
utilizes shiny:::generateOptions
internally. A peek into the source reveals that altering the style of individual checkboxes isn't a simple feat as they all share the same class="checkbox"
by default (a referenced response only covers setting a universal style for all choices).
The only solution I can suggest is directly injecting raw HTML into your UI. However, even this method gets complex because you cannot apply styles (like borders) directly to the checkbox element to influence its display, as explained in the aforementioned response. While exploring CSS myself, it seems that building new HTML checkboxes from scratch and layering them over the default ones might be the workaround (although hiding the default checkboxes successfully has proven challenging).
Below is a functional example catered to your requirements with its corresponding output displayed after the code snippet. Each scenario employs distinct wrappers (.my_checkBox_red
, .my_checkBox_blue
, and .my_checkBox_grey
). There may exist a more efficient approach by just adjusting the relevant styles (color:
, background-color:
), but I haven't cracked this puzzle yet. Another enhancement could involve automating the lengthy HTML string generation, although I lack the bandwidth to tackle this at present. For those interested, delving into the shiny function checkBoxGroupInput
or shiny:::generateOptions
serve as great starting points, or build a personalized function with utilities like sprintf
, paste
, and so forth.
Hope this sheds some light on your query!
(function(){
var themeSheet = document.createElement("style");
themeSheet.type = "text/css";
var cssString = '.my_checkBox input[type="checkbox"]+span {margin-left:10px};'
+ ' .my_checkBox input[type="checkbox"]:checked~label {font-weight:bold;}';
themeSheet.innerHTML = cssString;
document.head.appendChild(themeSheet);
}());
https://i.sstatic.net/7uc20.png