0

我有一个 selectInput 小部件,它允许选择多个输入。我想在每个选择选项上添加一个小彩色点,以便将其用作基于输入生成的相应绘图的图例。

selectInput("selectedSensors", "Select Climatic Condition(s) :",
                choices = c("Temperature" = "5a",
                  "Relative Humidity" = "5b",
                  "Pressure" = "5c",
                  "Mass Density of Particles in air (diam < 2.5μm)" = "0a",
                  "Mass Density of Particles in air (diam < 10μm)" = "0b",
                  "Wind Speed" = "6"), multiple = TRUE,
                selected = c("5b", "5a", "6"))

我尝试遵循这种方法,但由于我没有可用的现有图像,我认为它不适合我的需要。我还尝试icon("circle")在每个下拉选项上插入一个圆圈图标,然后我想尝试着色,但无法做到。

4

1 回答 1

1

在此处输入图像描述

library(shiny)

shinyApp(
  ui = fluidPage(
    selectizeInput(
      "variable", "Variable:",
      choices = 
        c("<span style='color:red;font-size:30px;vertical-align:bottom'>&bull;</span>&nbsp;Cylinders" = "cyl",
          "<span style='color:green;font-size:30px;vertical-align:bottom'>&bull;</span>&nbsp;Transmission" = "am",
          "<span style='color:blue;font-size:30px;vertical-align:bottom'>&bull;</span>&nbsp;Gears" = "gear"),
      options = list(render = I("
      {
        item:   function(item, escape) { return '<div>' + item.label + '</div>'; },
        option: function(item, escape) { return '<div>' + item.label + '</div>'; }
      }
    "))
    ),
    tableOutput("data")
  ),
  server = function(input, output) {
    output$data <- renderTable({
      mtcars[, c("mpg", input$variable), drop = FALSE]
    }, rownames = TRUE)
  }
)
于 2020-11-10T11:47:43.370 回答