Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative paths to dir above root? #29

Closed
pat-s opened this issue Jan 20, 2017 · 13 comments
Closed

Relative paths to dir above root? #29

pat-s opened this issue Jan 20, 2017 · 13 comments

Comments

@pat-s
Copy link
Collaborator

pat-s commented Jan 20, 2017

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
---
@yihui
Copy link
Owner

yihui commented Jan 20, 2017

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.

@pat-s
Copy link
Collaborator Author

pat-s commented Jan 20, 2017

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. 😊

@yihui
Copy link
Owner

yihui commented Jan 20, 2017

Yep, I understand. I ran into this issue myself two weeks ago, but I didn't have time to consider a fix.

@yihui
Copy link
Owner

yihui commented Jan 25, 2017

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').

@jvcasillas
Copy link
Contributor

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.

@yihui
Copy link
Owner

yihui commented Jan 25, 2017

@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.

@wjhopper
Copy link

wjhopper commented Jan 15, 2020

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?

@tcgriffith
Copy link
Collaborator

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?

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

Here is my example repo for xaringan+jekyll+ghpages
Result

@wjhopper
Copy link

wjhopper commented Jan 16, 2020

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.

@daijiang
Copy link

Did rmarkdown::render() reverted to the old behavior recently? At March 2021, I still can refer ../style.css and render it without problem (the generated html file used relative path). But today, I render the xaringan slides again (without changing anything, just deleted the html and try to rebuild), the generated html file used absolute path, which can be a problem when deploying online. Just report here; and sorry for not providing a reproducible example.

@yihui
Copy link
Owner

yihui commented Aug 16, 2021

@daijiang That sounds like a bug. It'll be great to file a new issue with a minimal reproducible example (you can upload a zip file containing the Rmd and css). Thanks!

@daijiang
Copy link

daijiang commented Aug 16, 2021

Here is an example. Note that no matter which way to generate the html (make at the root or use the knit button of RStudio), the line 10 of 01_about/presentation.html has the absolute path there. Thanks @yihui
example.zip

@cderv
Copy link
Collaborator

cderv commented Aug 17, 2021

@daijiang I created a new issue to follow that in its own thread. That is better to do so that just discussing in a closed one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants