【问题标题】:R shiny: checkboxGroupInput Insert a placemark between checkboxesR闪亮:checkboxGroupInput在复选框之间插入地标
【发布时间】:2021-01-15 17:30:24
【问题描述】:

我需要在复选框之间插入文本或标签。如何做到这一点?

【问题讨论】:

    标签: javascript css r checkbox shiny


    【解决方案1】:

    如果您使用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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-09
      • 2021-09-17
      • 2015-09-01
      • 1970-01-01
      相关资源
      最近更新 更多