繁体   English   中英

R 闪亮:checkboxGroupInput 在复选框之间插入一个地标

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM