我能够调整 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)
这是我的原始答案,它为选中元素设置标签样式,以防对其他人有用:
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)