0

The bookdown reference for SQL chunks states that:

If you need to bind the values of R variables into SQL queries, you can do so by prefacing R variable references with a ?.

But, how do you use R variables in css code chunks?

2
  • Could you post an example? It's not clear what you want: do you want a chunk that outputs CSS that affects the document, or CSS that is displayed because your document is talking about CSS as a language? Commented Dec 4, 2021 at 20:20
  • @user2554330 I am talking about a chunk that outputs CSS that affects the document. For example I would like to define the color of an element according to the current bootstrap theme, using something like bs_get_variables(bslib::bs_current_theme(), "primary") Commented Dec 4, 2021 at 20:40

1 Answer 1

2

If you want to output CSS code that affects the document, I'd use the glue package to do the substitutions, in an R code chunk that has echo=FALSE, results='asis'. For example,

```{r css, echo=FALSE, results='asis'}
margin <- 40

library(glue)
cat(glue(.open = "<<", .close = ">>", "
<style>
h1 {
  margin-left: <<margin>>px;
}
</style>
"))
```

would put the parts between <style> ... </style> into your document, substituting for R variables whereever it sees a variable name in double angle brackets, e.g. <<margin>> in my example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.