asahi
October 3, 2020, 8:52pm
1
I'd like to construct a table within a for loop, but the html output shows raw html as opposed to rendered html. I'm thinking that maybe print()
is the issue, but if I don't use print()
, then nothing gets included in the html output.
Here's my code:
library(gt)
for (i in 1:2) {
exibble %>% gt() %>% print()
}
And here's what the output looks like:
cderv
October 5, 2020, 8:21am
2
If you are outputing some HTML or markdown directly from the chunk, you need to use results='asis'
as a chunk option.
```{r, results='asis'}
library(gt)
for (i in 1:2) {
exibble %>% gt() %>% print()
}
```
See https://bookdown.org/yihui/rmarkdown-cookbook/results-asis.html
gt
output are also Rmardkown compatible so you can create a list with you tables, and output theme individually in chunks or inline code. Try that:
```{r}
library(gt)
gts <- lapply(1:2, function(i) exibble %>% gt())
```
`r gts[[1]]`
`r gts[[2]]`
asahi
October 5, 2020, 2:41pm
3
Thanks a lot. Much appreciated!
1 Like
system
Closed
October 12, 2020, 2:41pm
4
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.