html kable_styling not showing output in a for loop

℡╲_俬逩灬. 提交于 2021-01-29 08:15:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!