在 selectInput 小部件下拉选项上添加彩色点
Adding colored dots on selectInput widget dropdown options
我有一个 select 输入小部件,它允许 select 编辑多个输入。我想在每个 select 选项上添加一个小彩色点,以便将其用作根据输入生成的相应图的图例。
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")
然后我想尝试着色,但无法做到。
library(shiny)
shinyApp(
ui = fluidPage(
selectizeInput(
"variable", "Variable:",
choices =
c("<span style='color:red;font-size:30px;vertical-align:bottom'>•</span> Cylinders" = "cyl",
"<span style='color:green;font-size:30px;vertical-align:bottom'>•</span> Transmission" = "am",
"<span style='color:blue;font-size:30px;vertical-align:bottom'>•</span> 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)
}
)
我有一个 select 输入小部件,它允许 select 编辑多个输入。我想在每个 select 选项上添加一个小彩色点,以便将其用作根据输入生成的相应图的图例。
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")
然后我想尝试着色,但无法做到。
library(shiny)
shinyApp(
ui = fluidPage(
selectizeInput(
"variable", "Variable:",
choices =
c("<span style='color:red;font-size:30px;vertical-align:bottom'>•</span> Cylinders" = "cyl",
"<span style='color:green;font-size:30px;vertical-align:bottom'>•</span> Transmission" = "am",
"<span style='color:blue;font-size:30px;vertical-align:bottom'>•</span> 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)
}
)