问题
I want to use kable inside a for loop to generate a lot of tables in a HTML rmarkdown. I was looking for solutions and most of them are solved using the wrapper print around kable code. But when I want to generate html table outputs with kable_styling, this solution didn't work! For example:
table <- tibble(a = c(1:10),
b = letters[1:10])
for(each in 1:2) {
print(table %>%
kable())
cat("<br>")
}
This generate two simple tables.
But when I try:
table <- tibble(a = c(1:10),
b = letters[1:10])
for(each in 1:2) {
print(table %>%
kable() %>%
kable_styling("striped"))
cat("<br>")
}
Nothing happens! And that's only for html outputs. With latex it's ok. What should I do?
回答1:
Add htmltools::HTML()
to your pipe:
table %>%
kable() %>%
kable_styling("striped") %>%
htmltools::HTML() %>%
print
来源:https://stackoverflow.com/questions/54318047/html-kable-styling-not-showing-output-in-a-for-loop