【发布时间】:2021-01-15 17:30:24
【问题描述】:
【问题讨论】:
标签: javascript css r checkbox shiny
【问题讨论】:
标签: javascript css r checkbox shiny
如果您使用checkboxGroupInput,您可以使用choiceName 参数呈现其他HTML 元素。在下面的示例中,我使用 Shiny tags 定义了标记并将值作为列表传递
library(shiny)
ui <- tagList(
tags$head(
tags$style(
".label {
display: inline-block;
padding: 0;
margin: 6px 0;
}",
".label span {
padding: 3px;
color: #ffffff;
}",
".label .fruit {
background: green;
}",
".label .veggies {
background: #2d7ddd;
}",
".label .meat {
background: red;
}"
)
),
tags$main(
tags$h2("Custom Checkbox"),
checkboxGroupInput(
inputId = "food",
label = NULL,
choiceNames = list(
tags$p(class="label", tags$span(class = "fruit", "fruit"), "Grapes"),
tags$p(class="label", tags$span(class = "fruit", "fruit"), "Apples"),
tags$p(class="label", tags$span(class = "veggies", "veggies"), "Carrots"),
tags$p(class="label", tags$span(class = "veggies", "veggies"), "Celery"),
tags$p(class="label", tags$span(class = "meat", "meat"), "Beef"),
tags$p(class="label", tags$span(class = "meat", "meat"), "Chicken")
),
choiceValues = list(
"apples",
"grapes",
"carrots",
"celery",
"beef",
"chicken"
)
)
)
)
server <- function(input, output, session) {
observe(print(input$food))
}
shinyApp(ui, server)
【讨论】: