[英]R shiny: checkboxGroupInput Insert a placemark between checkboxes
如果您使用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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.