簡體   English   中英

css - RShiny 小部件:如何為 radioButtons() 和 checkboxGroupInput() 着色?

[英]css - RShiny widgets: How to color the radioButtons() and checkboxGroupInput()?

我在我的 RShiny 應用程序中使用了許多不同的checkboxGroupInput()radioButtons() ,一個代碼片段如下所示:

checkboxGroupInput(inputId = "maDays", label = "Select Trading Days", 
                                      choices = c("Monday", "Tuesday", "Wednesday", "Thursday",
                                                  "Friday", "Saturday", "Sunday"),
                                      selected = c("Monday", "Tuesday", "Wednesday", "Thursday",
                                                   "Friday"), 
                                      inline = TRUE),
radioButtons(inputId = "maTimeGran", label = "Select Time Granularity", 
                                choices = c("Hourly" = "hour", "Daily" = "day", 
                                            "Weekly" = "week"),
                                selected = "day")

並給出:

在此處輸入圖像描述 在此處輸入圖像描述

現在我的問題是:如何使用css -tag更改所有選擇的單選按鈕(按鈕,而不是文本)和復選標記(不是文本)的顏色? 我喜歡的顏色是#007d3c

我能夠適應https://dev.to/kallmanation/styling-a-radio-button-with-only-css-4llc的方法來使其工作。 (復選框在選中時具有純色填充顏色而不是復選標記。)

這是代碼:

library(shiny)

ui <- fluidPage(
    tags$head(
        tags$style(HTML("
                    label > input[type='radio'] {
                        opacity: 0;
                        position: absolute;
                    }
                    label > input[type='radio'] + *::before {
                        content: '';
                        margin: 4px 0 0;
                        width: 13px;
                        height: 13px;
                        position: absolute;
                        margin-left: -20px;
                        border-radius: 50%;
                        border-style: solid;
                        border-width: 0.1rem;
                        border-color: #007d3c;
                    }
                    label > input[type='radio']:checked + *::before {
                        background: radial-gradient(white 0%, white 30%, #007d3c 30%, #007d3c);
                                border-color: #007d3c;
                    }
                    label > input[type='checkbox'] {
                        opacity: 0;
                        position: absolute;
                    }
                    label > input[type='checkbox'] + *::before {
                      content: '';
                      position: absolute;
                      margin: 4px 0 0;
                      margin-left: -20px;
                      align: center;
                      width: 13px;
                      height: 13px;
                      margin-right: 1rem;
                      border-radius: 0%;
                      border-style: solid;
                      border-width: 0.1rem;
                      border-color: #007d3c;
                    }
                    label > input[type='checkbox']:checked + *::before {
                      content: '';
                      width: 13px;
                      height: 13px;
                      background-color: #007d3c;
                    }
                  "))
    ),
    checkboxGroupInput(inputId = "maDays", label = "Select Trading Days", 
                       choices = c("Monday", "Tuesday", "Wednesday", "Thursday",
                                   "Friday", "Saturday", "Sunday"),
                       selected = c("Monday", "Tuesday", "Wednesday", "Thursday",
                                    "Friday"), 
                       inline = TRUE),
    radioButtons(inputId = "maTimeGran", label = "Select Time Granularity", 
                 choices = c("Hourly" = "hour", "Daily" = "day", 
                             "Weekly" = "week"),
                 selected = "day")
)

server <- function(input, output) {
    ## put server code here
}

shinyApp(ui = ui, server = server)

這是我的原始答案,其中 styles 是檢查元素的標簽,以防這對其他人有用:

library(shiny)

ui <- fluidPage(
    tags$head(
        tags$style(HTML("
                  input:checked + span {
                    color: #007d3c;
                  }
                  "))
    ),
    checkboxGroupInput(inputId = "maDays", label = "Select Trading Days", 
                       choices = c("Monday", "Tuesday", "Wednesday", "Thursday",
                                   "Friday", "Saturday", "Sunday"),
                       selected = c("Monday", "Tuesday", "Wednesday", "Thursday",
                                    "Friday"), 
                       inline = TRUE),
    radioButtons(inputId = "maTimeGran", label = "Select Time Granularity", 
                 choices = c("Hourly" = "hour", "Daily" = "day", 
                             "Weekly" = "week"),
                 selected = "day")
)

server <- function(input, output) {
  ## put server code here
}

shinyApp(ui = ui, server = server)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM