2

I'm trying to add a favicon to my R Shiny app and I want to use a local image file so it can run without Internet connectivity. Using the example Emms gave here I've got a program that will display the favicon when it's using the NOAA logo's url. However, when I saved that exact image to my computer, I've not been able to get it to display. I've tried:

  1. feeding the href parameter a complete file path "C:/Users/...favicon.ico"
  2. feeding the href parameter only a file path that begins where the current working directory (viewed with getwd()) leaves off
  3. putting the downloaded NOAA logo .ico into a folder called "www" and placing it with my project/where my current directory is viewing (I don't know if guidance on folders named 'www' applied to local readings, but I figured I'd try it anyway)
  4. According to Giancarlo Tamburello's answer on the same page, I tried using this site to encode that same NOAA logo as a Base 64 character string--this required changing the whole function a bit, so that I assigned rel="icon", href="data:image/x-icon;base64,[my base 64 string]", and type="image/x-icon"

Nothing I've done with filepaths (or with the base 64 string) has resulted in anything other than Google Chrome's favicon placeholder. Any solution that works with filepaths or with base 64 would satisfy my requirement of being able to run without Internet connectivity.

I'm running R 4.0.2 with Windows 10 Pro OS on a 64-bit OS and launching into Google Chrome.

  • 1
    **www** must be a subfolder of the folder containing the Shiny app. This way is the right one. – Stéphane Laurent Aug 27 '20 at 23:20
  • Except www is a subfolder of the folder containing the Shiny app, and it holds nothing but the favicon.ico file (point three). Just to be sure, I restructured my Shiny app to inhabit a folder all its own containing just the global.R, ui.R, and server.R files and the www folder...and launching it from RStudio still doesn't work. I can give it a url and the online favicon will display, but I can get nothing from a local filepath (either a complete one 'C;/Users...' or one that begins www, or includes the .ico file name--nothing). – Non-Contradiction Aug 31 '20 at 21:09
  • I've checked my code. I'm using `rel = "shortcut icon"`, not `"icon"`. And this works. – Stéphane Laurent Sep 02 '20 at 13:44
  • I tried using "shortcut icon" with all of those filepath options for a www subdirectory and none of them worked. Is there a specific library or something that I should be including? – Non-Contradiction Sep 04 '20 at 17:11
  • Tried everything given online. Looks like there is no solution. :( – agent18 Oct 28 '20 at 21:56

2 Answers2

0

I noticed that when rendering a shiny R markdown into html, knitr copies all static assets into a <notebook_name>_files folder. This however doesn't work when an asset is referenced inside an include, as below. In such cases you can use this workaround (e.g. if your notebook is called index.Rmd):

  • in index.Rmd:
---
title: "Favicon"
output: 
  html_document:
    includes:
      in_header: "favicon.html" 
---

then also place the favicon as an image somewhere in your document:

![](favicon-32x32.png)
  • then in your favicon.html:
<link rel="shortcut icon" href="index_files/favicon-32x32.png">

knitr will copy the favicon image into it's static folder because it's present as an image in your document, which can then can also be referenced to display the favicon ;)

isthisthat
  • 143
  • 1
  • 10
0

You could just paste a base-64 encoded favicon HTML snippet into your R Markdown file, for instance copied from https://www.codegrepper.com/code-examples/html/html+favicon+base64:

<link rel="icon" type="image/png" sizes="16x16" href="data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAMFBMVEU0OkArMjhobHEoPUPFEBIu
O0L+AAC2FBZ2JyuNICOfGx7xAwTjCAlCNTvVDA1aLzQ3COjMAAAAVUlEQVQI12NgwAaCDSA0888G
CItjn0szWGBJTVoGSCjWs8TleQCQYV95evdxkFT8Kpe0PLDi5WfKd4LUsN5zS1sKFolt8bwAZrCa
GqNYJAgFDEpQAAAzmxafI4vZWwAAAABJRU5ErkJggg==" />
thomasswilliams
  • 388
  • 2
  • 9