I love Yihui's knitr package, and I know from the tutorials that it can put R into html documents. I want to go the other way -- I want to put some html into a grid graphics object. Is that possible in knitr, or any other library? Specifically, I am looking for a way to:
Style text using HTML (basic css and tables, mostly)
Wrap it up in a grob
Arrange/insert the grob using grid graphics, combining it with other grobs (ggplot charts, etc.)
I've searched on the knitr list and looked into grid graphics. It has a textGrob function but formatting options aren't robust enough for what I am looking for. There's a SO question that's in the ballpark but doesn't cover what I'm looking for. Here's a silly reproducible example that imitates the structure of my real document.
library(gridExtra)
#minimal valid object
rect = rectGrob()
text1 <- textGrob(
label = "textGrobs let you write text"
,x = unit(0.5, "npc"), y = unit(0.5, "npc")
,just = "centre"
,gp = gpar(col = "black", fontsize = 12)
)
text2 <- textGrob(
label = "but is there a graphics object that takes HTML?"
,x = unit(0.5, "npc"), y = unit(0.5, "npc")
,just = "centre"
,gp = gpar(col = "black", fontsize = 12)
)
#first split the box
top_box <- arrangeGrob(text1, text2, ncol = 2)
#put that together into a column
left_column <- arrangeGrob(
top_box, rect, rect
,nrow = 3
,heights = c(1, 2, 2)
)
grid.arrange(left_column, rect, widths = c(4/5, 1/5), ncol = 2)
I'd like to replace one of those empty rectangular grobs below with some text with HTML.
Thanks!