我正在try 在R中创建一个分页的pdf报告,使用PAGE DOWN和htmlTools::Taglist.报告中的每一页都应该汇集单一站点的实地调查结果,主要是图像和表格.
呈现内容本身并不是问题.但是,当我try 在标记列表中嵌套html元素时,会呈现父元素和第一个子元素,而"孙"元素则不会.相反,孙辈在其父级div中显示为文本.为什么会这样,我如何绕过它?
我想这样嵌套div的原因是,这将是一种方便的方法,可以确保所有属于一起的内容实际上最终在pdf中的同一页面上,即通过将属于一起的元素包装在一个主容器中,我可以更容易地控制尺寸.
不知道问题出在哪里,S是htmlTools的问题,html的问题,还是me的问题.提前感谢您的帮助!
请看下面这个简单的例子,它再现了"问题",以及我得到的输出图像.
---
title: "My Report"
output:
pagedown::html_paged:
toc: false
number_sections: false
fontsize: 8pt
classoption: a4paper
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(shiny)
library(htmltools)
```
```{r echo=FALSE, results='asis'}
# URL to the R logo image
r_logo_url <- "https://www.r-project.org/logo/Rlogo.png"
# Create tagList with html elements
my_tagList <- tagList(
p("This is text and the R Logo outside of parent div - works as expected"),
img(src = r_logo_url, alt = "R Logo", style = "width: 100px;"),
div(
style = "border: 2px solid blue;",
p("This is the R Logo within the parent div - works as expected"),
img(src = r_logo_url, style = "width: 100px;"),
# Here is where the problems start - the div is rendered, but elements within it are not. Instead they show up as text. Why, and how to get around it?
div(
style = "border: 2px solid black; margin: 5px;",
p("This text and the image below, within child div, are not rendered. They only show up as text. Why?", style = "border-bottom: 2px solid black;"), # text within grandchild is not rendered
img(src = r_logo_url, style = "width: 100px;") # image within child div
)
)
)
# Print or render the tagList
print(my_tagList)
```
以下是我从运行该示例得到的输出: Output from code个