Is it possible to get a css variable in RMD?

Viewed 42

I have an .Rmd file where I would like to adapt the style depending on whether it is a mobile version or not - in css it is quite easy to check the window width with @media;

But then, let's say I have a root variable

--mobile: 1;

How would I be able to use this variable in an R chunk of a .Rmd file, i.e. how could I retrieve this variable?

1 Answers

I think this is essentially impossible, unless you are just parsing a .css file that you're intending to include:

CSS values can only be determined by looking at the .html file produced from the .Rmd file, but at the time the R code is running, the .html file hasn't yet been produced.

One way to get a guess at the value might be to have your R code render an .html file from the same .Rmd you're currently using (and you'll have to be careful that the nested .Rmd doesn't render itself again, in an infinite recursion). Then parse that .html file to find the active value of that variable within the code chunk that wants to know it.

Related