我正在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

推荐答案

不要使用

print(my_tagList)

只需使用

my_tagList

将自动打印返回值.这个问题的原因在第this github issue节中有描述.print()函数使用缩进部分格式化输出,标记处理器将其解释为代码块.

Html相关问答推荐

srcset和大小总是下载最大的

Tailwincss:自动设置网格高度

如何防止第二列中的内容影响第一列中内容的位置?

为什么在添加文本时网格区域会调整大小?

如何影响flex项目中的flex-gap收缩顺序和文本换行顺序?

如何突破安莉得分

如何在R中渲染Quarto文档时动态设置html文件名

HX-POST未使用正确的操作(路径)

如何使用css横向显示英文和中日韩文字?

在R中从网页上的特定iframe中提取图形数据

从html文件中提取元素的Python BeautifulSoup

布局更改时的转换

为什么字体大小而不是 colored颜色 属性适用于元素?

防止HTML输入中出现负数但接受小数

暗模式转换器

不理解 CSS 中的 General sibling combinator (~)

如何在单击按钮时切换 Blazor 中的类?

变换元素以适应高度(Angular,SCSS)

使用 tailwind css 将 HTML/CSS/JS 站点转换为 React App

Bootstrap Grid System col 无法正常工作