gpt4 book ai didi

r - 如何正确重写 R Shiny 的函数 icon() 以包含 Font-Awesome Pro 图标?

转载 作者:行者123 更新时间:2023-12-04 09:45:23 25 4
gpt4 key购买 nike

这是基于另一个线程提出相同问题的后续问题:R Shiny: how to use fontawesome pro version with the icon function? .

我尝试了接受的答案,但它仅适用于免费图标。其他图标不渲染,即什么也没有出现。

这是我重写自定义 my_icon() 的失败尝试,从上面的链接线程“ fork ”。我的目标是正确计算专业图标类 fas , far , fal , fad ,假设 iconClass例如,应该是 fas fa-alien (如 https://fontawesome.com/icons/alien?style=solid )。

我的更改仍然没有效果。 Pro 图标一直没有出现。所以我一定错过了一些基本的东西。

请注意,我更改了 ./www/shared进入 ./shared/避免警告:

Warning: Found subdirectories of your app's www/ directory that conflict with other resource URL prefixes. Consider renaming these directories: 'www/shared'


my_icon = function (name, class = NULL, lib = "font-awesome") {

prefixes <- list(`font-awesome` = "fa", glyphicon = "glyphicon")
prefix <- prefixes[[lib]]
if (is.null(prefix)) {
stop("Unknown font library '", lib, "' specified. Must be one of ",
paste0("\"", names(prefixes), "\"", collapse = ", "))
}
iconClass <- ""
if (!is.null(name) & is.null(class)) {
prefix_class <- prefix
iconClass <- paste0(prefix_class, " ", prefix, "-", name)
} else if (!is.null(name) & !is.null(class)) {
iconClass <- paste0(prefix, '-', name)
iconClass <- paste(class, iconClass)
}

# print(iconClass)
iconTag <- tags$i(class = iconClass)
if (lib == "font-awesome") {
htmlDependencies(iconTag) <- htmlDependency("font-awesome",
"5.13.0", "./shared/fontawesome",
stylesheet = c("css/all.min.css"))
}
htmltools::browsable(iconTag)
}

最佳答案

这个问题是在一年前提出的,但如果其他人正在寻找答案:有一个模块 rstudio/fontawesome为了这。 shiny::icon()实现使用 fa_i()在内部,但如果您调用 fa_i()您自己应该能够使用“html_dependency”参数添加“专业”图标。从文档中,论点:

Provides an opportunity to use a custom html_dependency object (created via a call to htmltools::htmlDependency()) instead of one supplied by the function (which uses Font Awesome's free assets and are bundled in the package). A custom html_dependency object is useful when you have paid icons from Font Awesome or would otherwise like to customize exactly which icon assets are used (e.g., woff, woff2, eot, etc.). By default, this is NULL where the function internally generates an html_dependency.

关于r - 如何正确重写 R Shiny 的函数 icon() 以包含 Font-Awesome Pro 图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62151996/

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