34

I wanted to add a favicon to my WebApp

I'm using this line, but it doesn't work:

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

inside the ui.R script and outside the shinyUI() function. Also I have the image.png where the server.R and ui.R are. (I've also tried putting it inside the folder /www )

Do you know how to do it? Thanks

4 Answers 4

43

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

4
  • 7
    Thank you, Joe. It was really easy. Shiny automatically detects there is a favicon in /www/favicon.ico
    – Geiser
    May 8, 2015 at 7:25
  • 1
    tags$head solution stopped working for me after enabling HTTPS for the site, most likely because the tags$head href was http. Putting favicon at /srv/shiny-server/favicon.ico worked for me, though.
    – ZN13
    Jan 10, 2017 at 9:29
  • 1
    When I deploy it on shinyapps.io then it does not show the logo. Only works in the local. Aug 8, 2017 at 15:03
  • 5
    I got it working—with a local run—using tags$head(tags$link(rel="shortcut icon", href="favicon.ico")), with the image file in the 'www' directory.
    – Dale Kube
    Aug 26, 2019 at 15:05
4

You can convert your favicon into base64 text (check favicon.cc website, they already do it) and write:

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(
3

A possible problem the OP is having is that the favicon filename should be favicon.ico and not image.png.

Some additional details here: favicon.png vs favicon.ico - why should I use PNG instead of ICO?

The important part being:

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.

1
  • 2
    Your quote contradicts your answer. The OP has specified a shortcut via a link tag.
    – Daniel
    Jun 18, 2017 at 22:52
2

I was able to get favicon to work in r shiny using this code on both internet explorer and chrome:

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)

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.