rstudio / pagedown

Paginate the HTML Output of R Markdown with CSS for Print
https://pagedown.rbind.io
Other
886 stars 129 forks source link

Read text from an R object or external csv file #181

Open filippogambarota opened 4 years ago

filippogambarota commented 4 years ago

I'm creating some tickets (using the business cards template) for an event and I would like to dynamically fill the appropriate fields according to variables in a dataset. Let's say that I have a dataset with a name, surname and institution and I want to generate n tickets according to the correct institution and name. Could it be possibile? I cannot find a way to integrate R objects when creating a ticket using the pagedown example

::: {.wrapper data-repeat="6"}
[John Doe]{slot="name"}
[Mister Nobody]{slot="title"}
[+1 777-777-7777]{slot="phone"}
[john.doe@example.com]{slot="email"}
[my.domain.com]{slot="url"}
:::
RLesur commented 4 years ago

Maybe you could dynamically build the YAML like here. Here's a minimal example:

---
logo: "https://raw.githubusercontent.com/rstudio/pagedown/master/inst/examples/pagedown_hex.svg"
paperwidth: 8.5in
paperheight: 11in
cols: 4
rows: 3
output: pagedown::business_card
---

```{r process-data}
# assume that we have a data.frame with name, surname and institution
df <- data.frame(name = c("Hermione", "Jane"),
                 surname = c("Granger", "Doe"),
                 institution = c("Hogwarts", "University of Nowhere"))

person <- apply(df, 1, function(x) {
  list(
    name = paste(x["name"], x["surname"]),
    address = x["institution"]
  )
})
```

---
```{r write-yaml, results='asis'}
cat(yaml::as.yaml(list(person = person)))
```
---