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:
feeding the href parameter a complete file path "C:/Users/...favicon.ico"
feeding the href parameter only a file path that begins where the current working directory (viewed with getwd()) leaves off
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)
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.
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 ;)
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==" />
Related
Is there a way to automatically apply some post-processing to html files generated from R Markdown?
For example, if we use MathJax to render LaTeX code (primarily in RStudio), the resulting html file includes src= links to load MathJax from a CDN. The problem is, we also need to be able to display these files on internal network without internet access, and those links need to be replaced to point to a local copy of MathJax.
It would be convenient if there was some hook that I could use to do that after the html file is generated, but I haven't been able to find any.
If your post processing is specifically about MathJax, you might consider setting your output yaml to the following which will download local copies of libraries such as MathJax and link to them.
output:
html_document:
self_contained: FALSE
mathjax: local
Using the hugo-geo theme and RStudio, I've built a website on Netlify. My code is on GitHub (https://github.com/kathryn2/Website).
Issue I'm having: The initial page works great. Hyperlinks on left pane all work as intended. When selecting individual posts from the left pane (e.g., https://k22daugherty.netlify.com/post/how-heavily-armed-is-your-state/), formatting totally craps out. It's as if there's no theme and the site doesn't know what to do. I tried seeing if it's a lack of knitting the markdown pages and when I do that I get errors that the images cannot be found. This is my first stab with Rmarkdown (though I'm used to JupyterNotebook with Python), so any obvious fixes are worth mentioning.
Any help appreciated!
Try the following:
modify this filein the line 23 from
<link rel="stylesheet" href="/css/style.css">
to
<link rel="stylesheet" href="public/css/style.css">
If it does not work please notice that your github repository should be the public folder instead of the whole folder where you create your R project and where you are using blogdown.
Is it possible to include dygraphs chart or some of other js-object supported by htmlwidgets.org to Jekyll-run site from R?
I've tried different variants (Rmd -> Md or Rmd -> html) with no success. The best outcome I have, dyghraphs is included into html-code but doesn't show up on the page (example: http://quantviews.github.io/dygraphs-test/).
Is there any working examples of Jekyll-run site with dygraphs included from Rmd-files?
I think Jekyll is skipping the "libs" directory that's in your _posts folder. (I'm pretty sure it's designed not to process sub directories under "_posts".) The fix is to move the libs folder up and then update the links to point to the new location. For example:
Move the "_posts/libs" folder up one directory so it's sitting next to "_posts".
Add a "/" to the front of the URLs for all the <script src="libs/... links so they call from the docroot. Should look like: <script src="/libs/....
Add a "/" to the front of the URLs for all the <link href="libs/... links so they call from the docroot. Should look like: <link href="/libs/.....
That's it for the main fix. But, there is another bug too. In the _posts/2015-05-15-dygraphs-test.html file, there is a call to:
<script src="libs/dygraphs-binding-0.4.1/dygraphs.js"></script>
But the version 'dygraphs-binding' version in your current libs directory is 0.4.3. I tried just changing the directory name and that worked for me. (i.e. "/libs/dygraphs-binding-0.4.3/dygraphs.js" becomes "libs/dygraphs-binding-0.4.1/dygraphs.js"). It would probably be better to actually line everything up, but that will at least get you working.
my solution:
render with rmarkdown::html_output, copy dygraph dependencies from header
create a new jekyll layout in _layouts/ with the dygraphs dependencies (changing libs to /libs as mentioned before)
run rmarkdown again, this time with rmarkdown::html_fragment to generate html without header
copy html fragment to _includes/
create a new blog post using layout specified in [2]
include html fragment in body of blog post using {% include html_fragment.html %}
I just asked this question: Why is Font Awesome only showing a square?.
The gist of it is that my font-awesome.min.css file was not working. I was getting 404 errors when trying to load icons from it. Someone gave the ridiculous suggestion of changing:
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
to
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
I tried their suggestion with confidence that it would not change anything, but it worked!
The code in MyProject/font-awesome/css/font-awesome.min.css (the filepath is correct) is identical to the code at //maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css.
Why is it that the CDN works, but my local copy gives me 404 errors?
Some clarification:
The file is being found when I try to link to the relative file (not using the CDN). The images within the CSS come up with 404. But with identical code at the CDN, there is no 404 for the images. I get the following error for each respective image:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:63343/MyProject/font-awesome/fonts/fontawesome-webfont.woff2?v=4.3.0
The CSS file refers to font files using relative URLs. So when you copy the CSS, you also have to copy the font folder to MyProject/font-awesome/fonts.
Basically, when you download the Font Awesome ZIP file, you should extract the entire thing into MyProject/font-awesome. This will get you the all the files and they'll be in the proper location.
You are pointing to the absolute url. Try changing it to relative to Home page. Ex: /font-awesome/css/font-awesome.min.css.
I create a R Markdown file in RStudio , then I click on the Knit HTML button on the top of the screen to create and save an HTML page which I want to use elsewhere, say store it on my server.
The problem with the HTML file, is that it contains
<script type="text/javascript" src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
which is not valid anymore, and when I edit the HTML and change the source to the following it works.
https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
Any way I don't have to edit every time the HTML, but have the correct source from RStudio?
This was changed in the rmarkdown package just about a month ago (see this commit). You just need to install the latest version of the rmarkdown package:
> devtools::install_github("rstudio/rmarkdown")
(of course, you'll also need to install.packages("devtools") if you don't have devtools.)
Incidentally, even without this step, you can tell rmarkdown where you want to get MathJax from. This is useful if you want to point to a different CDN.
output:
html_document:
mathjax: https://d3eoax9i5htok0.cloudfront.net/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
Finally, you can eliminate your MathJax CDN dependency entirely by using mathjax: local to use a built-in copy of MathJax in rmarkdown (note that you'll also need to set self_contained: no to do this).