I placed my custom CSS file one directory above the .Rmd file. However, it is not recognized there.
output:
xaringan::moon_reader:
css: "../my-theme.css"
The same happens if I specify such a path for background-image in a layout slide
layout: true
background-image: url(../img/some-image.png)
background-size: cover
---
This is a known limitation due to the fact that I start a local web server using the directory of the Rmd file as the root directory, and you cannot go to upper directories of a web server. I'll see if I can come up with a fix.
Would be great! This would avoid having to copy theme.css and all related images x times into subfolders of all presentations but create one shared top-level folder for the theme content. :blush:
Yep, I understand. I ran into this issue myself two weeks ago, but I didn't have time to consider a fix.
Done. All you need to do is set your working directory to the parent directory before clicking the Infinite Moon Reader addin in RStudio, or call xaringan::inf_mr('path/to/your.Rmd').
Do you foresee making CSS files accesible without changing the working directory? For example, I am using xaringan to make slides for my class, which are inside a directory for the class website. The website has a site_libs directory where I keep all css. So I must I set the working directory to a folder that is rather out of the way, then use the path back to the .Rmd file to render the slides, and, finally, change the working directory back to the project root. I can keep the css in a more convenient place as a work around, but it seems like having complete control of the path without changing the working directory would probably be ideal.
@jvcasill You don't have to change the working directory, but you will have to type something like xaringan::inf_mr(cast_from = '..') in the console instead of clicking the RStudio addin "Infinite Moon Reader". You have to make sure the directory cast_from is the common parent directory of your CSS and Rmd (it does not have to be the direct parent, e.g. can be two levels up ../..). The first argument of inf_mr() can be omitted when the Rmd is currently open in the RStudio source editor, otherwise you have to type the Rmd filename.
I know this is a very old issue, but I just ran into it myself trying to integrate some xaringan slides into a jekyll site that already has an assets directory for css.
I understand that if you're using the "Infinite Moon Reader" live preview functionality, you should use the cast_from argument to set the root of the web server. But, is there any way around it when using rmarkdown::render() or the knit button in RStudio (besides change the working directory, which opens its own can of worms for knitting)? Or does the knit button rely on the webserver as well?
I know this is a very old issue, but I just ran into it myself trying to integrate some xaringan slides into a jekyll site that already has an assets directory for css.
I understand that if you're using the "Infinite Moon Reader" live preview functionality, you should use the
cast_fromargument to set the root of the web server. But, is there any way around it when usingrmarkdown::render()or the knit button in RStudio (besides change the working directory, which opens its own can of worms for knitting)? Or does the knit button rely on the webserver as well?
My understanding is that you can set the lib_dir: assets in the yaml header then you are good to go
full header:
title: "Presentation Ninja"
subtitle: "โ<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, Inc."
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: assets
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
Then knit in Rstudio would result in the following structure
.
โโโ assets
โย ย โโโ crosstalk
โย ย โโโ datatables-binding
โย ย โโโ datatables-css
โย ย โโโ dt-core
โย ย โโโ htmlwidgets
โย ย โโโ jquery
โย ย โโโ leaflet
โย ย โโโ leaflet-binding
โย ย โโโ leafletfix
โย ย โโโ Proj4Leaflet
โย ย โโโ remark-css
โย ย โโโ rstudio_leaflet
โโโ testit_files
โย ย โโโ figure-html
โโโ testit.html
โโโ testit.Rmd
Thanks for sharing @tcgriffith! But, I don't think this will work for me specifically. In your example, the xaringan slide deck testit.Rmd file is at the root (where the assets folder also is), whereas mine is in a subfolder like so:
โโโ _config.yml
โโโ index.md
โโโ _labs
โ โโโ Lab 01
โ โโโ Introduction.Rmd ## Xaringan slides here
โโโ assets
โ โโโcss
โ โโโ custom.css
If I just put lib_dir: assets, knitting just creates a new directory named assets in the same sub directory as the slides, like so:
โโโ _config.yml
โโโ index.md
โโโ _labs
โ โโโ Lab 01
โ โโโ Introduction.Rmd
โ โโโ Introduction.html
โ โโโ assets ## <- just adds this
โ โโโ remark-css-0.0.1
โ โโโ default.css
โ โโโ default-fonts.css
โโโ assets
โ โโโ css
โ โโโ custom.css
So, I think it comes back to the core issue of accessing files above the "root", where "root" is the directory where your .Rmd is stored.
Most helpful comment
My understanding is that you can set the
lib_dir: assetsin the yaml header then you are good to gofull header:
Then knit in Rstudio would result in the following structure
Here is my example repo for xaringan+jekyll+ghpages
Result