我在 Shiny 的应用程序中有以下代码,让用户可以选择他们想在绘图上使用的点形状。
selectInput("pch", "Point shape",c("15","16","17","18"),selectize = TRUE,multiple=F)
出于审美原因(也是实际原因),我想要 4 个绘图字符的 4 个图像,而不仅仅是数字 15、16、17、18。
同样,在这个例子中,
selectInput("col", "Colour",colours(),selectize = TRUE,multiple=F)
除了颜色的文本名称,我还想使用颜色图像或颜色选择器。
我想到的是以下内容:
谢谢
最佳答案
还有pickerInput
来自 shinyWidgets
,可以使用 html/css 自定义。有了它,您可以将任何图像或图标包含到选择小部件中。
但是,使用这种方法,图像必须已经存在。
library(shiny)
library(shinyWidgets)
df <- data.frame(
val = c("pal1","pal2", "pal3", "pal4")
)
df$img = c(
sprintf("<img src='https://d9np3dj86nsu2.cloudfront.net/image/eaf97ff8dcbc7514d1c1cf055f2582ad' width=30px><div class='jhr'>%s</div></img>", df$val[1]),
sprintf("<img src='https://www.color-hex.com/palettes/33187.png' width=30px><div class='jhr'>%s</div></img>", df$val[2]),
sprintf("<img src='https://www.color-hex.com/palettes/16042.png' width=30px><div class='jhr'>%s</div></img>", df$val[3]),
sprintf("<img src='https://www.stlawrencegallery.com/wp-content/uploads/2018/09/unique-navy-blue-color-palette-five-stunning-palettes-for-weddings-dark.jpg' width=30px><div class='jhr'>%s</div></img>", df$val[4])
)
ui <- fluidPage(
tags$head(tags$style("
.jhr{
display: inline;
vertical-align: middle;
padding-left: 10px;
}")),
pickerInput(inputId = "Id0109",
label = "pickerInput Palettes",
choices = df$val,
choicesOpt = list(content = df$img))
)
server <- function(input, output) {}
shinyApp(ui, server)
关于selectInput 中的 R Shiny 自定义图标/图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30486412/