gpt4 book ai didi

r - Shiny 的下拉输入(selectizeInput),带有超赞的图标

转载 作者:行者123 更新时间:2023-12-04 13:08:00 25 4
gpt4 key购买 nike

我想包括 Font Awesome Shiny 项目中的图标 selectizeInput .我怎么办?

最佳答案

这是一个函数,selectInputWithIcons ,这就完成了。
enter image description here

library(shiny)
library(fontawesome)
library(htmltools)


selectInputWithIcons <- function(
inputId, inputLabel, labels, values, icons, iconStyle = NULL,
selected = NULL, multiple = FALSE, width = NULL
){
options <- mapply(function(label, value, icon){
list(
"label" = label,
"value" = value,
"icon" = as.character(fa_i(icon, style = iconStyle))
)
}, labels, values, icons, SIMPLIFY = FALSE, USE.NAMES = FALSE)
render <- paste0(
"{",
" item: function(item, escape) {",
" return '<span>' + item.icon + '&nbsp;' + item.label + '</span>';",
" },",
" option: function(item, escape) {",
" return '<span>' + item.label + '</span>';",
" }",
"}"
)
widget <- selectizeInput(
inputId = inputId,
label = inputLabel,
choices = NULL,
selected = selected,
multiple = multiple,
width = width,
options = list(
"options" = options,
"valueField" = "value",
"labelField" = "label",
"render" = I(render),
"items" = as.list(selected)
)
)
attachDependencies(widget, fa_html_dependency(), append = TRUE)
}


ui <- fluidPage(
br(),
selectInputWithIcons(
"slctz",
"Select an animal:",
labels = c("I want a dog", "I want a cat"),
values = c("dog", "cat"),
icons = c("dog", "cat"),
iconStyle = "font-size: 3rem; vertical-align: middle;",
selected = "cat"
)
)

server <- function(input, output, session){

observe({
print(input[["slctz"]])
})

}


shinyApp(ui, server)

关于r - Shiny 的下拉输入(selectizeInput),带有超赞的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68509486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com