【问题标题】:Adding colored dots on selectInput widget dropdown options在 selectInput 小部件下拉选项上添加彩色圆点
【发布时间】:2020-11-10 19:47:43
【问题描述】:

我有一个 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"))

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

【问题讨论】:

    标签: r shiny shinywidgets


    【解决方案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)
      }
    )
    

    【讨论】:

      猜你喜欢
      • 2021-02-21
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多