闪亮的图标

Favicon in Shiny

我想将网站图标添加到我的 WebApp

我正在使用这条线路,但它不起作用:

HTML("<link rel=\"icon\" type=\"image/png\" href=\"image.png\" />")

在 ui.R 脚本内部和 shinyUI() 函数外部。我还有 image.png,其中 server.R 和 ui.R 是。 (我也试过把它放在文件夹 /www )

你知道怎么做吗?谢谢

If you're using a local runapp, then putting one in /www/favicon.ico should work, I believe.

You could also insert this somewhere in your UI:

tags$head(tags$link(rel="shortcut icon", href="URL-to-favicon"))

Joe Cheng

OP 可能遇到的问题是网站图标文件名应该是 favicon.ico 而不是 image.png。

这里有一些额外的细节:favicon.png vs favicon.ico - why should I use PNG instead of ICO?

重要的部分是:

All modern browsers (tested with Chrome 4, Firefox 3.5, IE8, Opera 10 and Safari 4) will always request a favicon.ico unless you've specified a shortcut icon via . So if you don't explicitly specify one, it's best to always have a favicon.ico file, to avoid a 404.

我能够在 Internet Explorer 和 chrome 上使用此代码使网站图标在 r shiny 中工作:

ui <- fluidPage(
  titlePanel(
    windowTitle = "NOAA",
    title = tags$head(tags$link(rel="shortcut icon", 
                                href="https://www.noaa.gov/sites/all/themes/custom/noaa/favicon.ico", 
                                type="image/vnd.microsoft.icon")))
###... rest of code
)

server <- function(input, output, session) {
###... rest of code
}

runApp(shinyApp(ui = ui, server = server), launch.browser = TRUE)

您可以将您的网站图标转换为 base64 文本(查看 favicon.cc 网站,他们已经这样做了)并写下:

ui <- function(){tagList(

fluidPage(


titlePanel(
  windowTitle = "Title that appears in the browser bar",
  title = tags$head(tags$link(rel="icon", 
                              href="data:image/x-icon;base64,AAABAAEAEBAQAAEAetc", 
                              type="image/x-icon")
                    )),

sidebarLayout( sidebarPanel(