- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下是带有 <details>
的 R-markdown 文档标签来创建可折叠的部分。
你能帮我渲染datatable
吗?来自 html 输出中的第 2 节?
最小可重现示例
### Section 1
<details> <summary>Click to expand</summary>
```{r, echo=FALSE}
head(iris)
```
</details>
### Section 2
<details> <summary>Click to expand</summary>
```{r, echo=FALSE}
DT::datatable(iris)
```
</details>
最佳答案
这不是一个真正的答案,但有点太长了,不能成为评论,所以我把它包括在这里。希望有人可以用它来得出一个实际的答案:
好消息是它绝对是“可能的”。坏消息是“这并不容易”。由于我对 web-dev 的了解有限,问题似乎是 DT::datatable
(或更准确地说 htmlwidgets:::print.html_widget
)在一个临时文件中创建一个完整的 html 网页,这是可视化 DT::datatable
的默认方法.文件本身看起来像
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<style>body{background-color:white;}</style>
<script src="lib/htmlwidgets-1.5.3/htmlwidgets.js"></script>
<script src="lib/jquery-1.12.4/jquery.min.js"></script>
<link href="lib/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet" />
<script src="lib/datatables-binding-0.16/datatables.js"></script>
<link href="lib/dt-core-1.10.20/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="lib/dt-core-1.10.20/css/jquery.dataTables.extra.css" rel="stylesheet" />
<script src="lib/dt-core-1.10.20/js/jquery.dataTables.min.js"></script>
<link href="lib/crosstalk-1.1.0.1/css/crosstalk.css" rel="stylesheet" />
<script src="lib/crosstalk-1.1.0.1/js/crosstalk.min.js"></script>
</head>
<body>
<div id="htmlwidget_container">
<div id="htmlwidget-cd5f37d21433eb2088ae" style="width:960px;height:500px;" class="datatables html-widget"></div>
</div>
<script type="application/json" data-for="htmlwidget-cd5f37d21433eb2088ae">{"x":{"filter":"none","data":[["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100","101","102","103","104","105","106","107","108","109","110","111","112","113","114","115","116","117","118","119","120","121","122","123","124","125","126","127","128","129","130","131","132","133","134","135","136","137","138","139","140","141","142","143","144","145","146","147","148","149","150"],[5.1,4.9,4.7,4.6,5,5.4,4.6,5,4.4,4.9,5.4,4.8,4.8,4.3,5.8,5.7,5.4,5.1,5.7,5.1,5.4,5.1,4.6,5.1,4.8,5,5,5.2,5.2,4.7,4.8,5.4,5.2,5.5,4.9,5,5.5,4.9,4.4,5.1,5,4.5,4.4,5,5.1,4.8,5.1,4.6,5.3,5,7,6.4,6.9,5.5,6.5,5.7,6.3,4.9,6.6,5.2,5,5.9,6,6.1,5.6,6.7,5.6,5.8,6.2,5.6,5.9,6.1,6.3,6.1,6.4,6.6,6.8,6.7,6,5.7,5.5,5.5,5.8,6,5.4,6,6.7,6.3,5.6,5.5,5.5,6.1,5.8,5,5.6,5.7,5.7,6.2,5.1,5.7,6.3,5.8,7.1,6.3,6.5,7.6,4.9,7.3,6.7,7.2,6.5,6.4,6.8,5.7,5.8,6.4,6.5,7.7,7.7,6,6.9,5.6,7.7,6.3,6.7,7.2,6.2,6.1,6.4,7.2,7.4,7.9,6.4,6.3,6.1,7.7,6.3,6.4,6,6.9,6.7,6.9,5.8,6.8,6.7,6.7,6.3,6.5,6.2,5.9],[3.5,3,3.2,3.1,3.6,3.9,3.4,3.4,2.9,3.1,3.7,3.4,3,3,4,4.4,3.9,3.5,3.8,3.8,3.4,3.7,3.6,3.3,3.4,3,3.4,3.5,3.4,3.2,3.1,3.4,4.1,4.2,3.1,3.2,3.5,3.6,3,3.4,3.5,2.3,3.2,3.5,3.8,3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.3,0.3,0.2,0.4,0.2,0.5,0.2,0.2,0.4,0.2,0.2,0.2,0.2,0.4,0.1,0.2,0.2,0.2,0.2,0.1,0.2,0.2,0.3,0.3,0.2,0.6,0.4,0.3,0.2,0.2,0.2,0.2,1.4,1.5,1.5,1.3,1.5,1.3,1.6,1,1.3,1.4,1,1.5,1,1.4,1.3,1.4,1.5,1,1.5,1.1,1.8,1.3,1.5,1.2,1.3,1.4,1.4,1.7,1.5,1,1.1,1,1.2,1.6,1.5,1.6,1.5,1.3,1.3,1.3,1.2,1.4,1.2,1,1.3,1.2,1.3,1.3,1.1,1.3,2.5,1.9,2.1,1.8,2.2,2.1,1.7,1.8,1.8,2.5,2,1.9,2.1,2,2.4,2.3,1.8,2.2,2.3,1.5,2.3,2,2,1.8,2.1,1.8,1.8,1.8,2.1,1.6,1.9,2,2.2,1.5,1.4,2.3,2.4,1.8,1.8,2.1,2.4,2.3,1.9,2.3,2.5,2.3,1.9,2,2.3,1.8],["setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","setosa","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","versicolor","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica","virginica"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th> <\/th>\n <th>Sepal.Length<\/th>\n <th>Sepal.Width<\/th>\n <th>Petal.Length<\/th>\n <th>Petal.Width<\/th>\n <th>Species<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"columnDefs":[{"className":"dt-right","targets":[1,2,3,4]},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false}},"evals":[],"jsHooks":[]}</script>
<script type="application/htmlwidget-sizing" data-for="htmlwidget-cd5f37d21433eb2088ae">{"viewer":{"width":450,"height":350,"padding":15,"fill":true},"browser":{"width":960,"height":500,"padding":40,"fill":false}}</script>
</body>
</html>
数据和标题显然会根据数据而变化。
DT::datatable(iris)
显示表格<details>
/</details>
<body>
的开头和结尾DT::datatable
你最终会发现它调用了
htmlwidgets:::print.html_widget
打开实际的 html 页面。这让我们可以重新创建一个脚本并提取小部件中使用的实际 html 代码:
#' Generate html and make dependencies available in directory for a DT::datatable
#'
#' @param x a data.frame or DT::datatable
#' @param dir the (root) directory for the project/dependencies. See details
#' @param background background for the html widget
#' @param libdir directory to export dependencies to
#'
#' @details This function generates the html that is usually generated when
#' printing DT::datatable, and exports dependencies to a given directory, making
#' it useful for embedding the html into a markdown file or shiny script, either
#' running and saving this in the pre-amble/header or interactively. "Dir"
#' can be used to specify the project root, with "libdir" specifying the path
#' relative from "dir" to place dependencies. Note that this likely enforces
#' the html file to be placed in the project root, and not a sub-folder of the
#' project.
datatable_html <- function(x, dir = getwd(), background = "white", libdir = 'lib'){
if(is.data.frame(x))
x <- DT::datatable(x)
#from htmlwidgets:::print.html_widgets
x <- htmltools::as.tags(x, standalone = TRUE)
#from htmltools::save_html (called by print.html_widgets
x <- htmltools::renderTags(x)
deps <- lapply(x$dependencies, function(dep) {
dep <- htmltools::copyDependencyToDir(dep,
libdir,
FALSE)
dep <- htmltools::makeDependencyRelative(dep, dir, FALSE)
dep
})
bodyBegin <- if (!isTRUE(grepl("<body\\b", x$html[1],
ignore.case = TRUE))) {
"<body>"
}
bodyEnd <- if (!is.null(bodyBegin)) {
"</body>"
}
c("<!DOCTYPE html>", "<html>", "<head>",
"<meta charset=\"utf-8\"/>", sprintf("<style>body{background-color:%s;}</style>",
htmltools::htmlEscape(background)),
htmltools::renderDependencies(deps, c("href", "file")), x$head, "</head>",
bodyBegin, # <=== body starts here, maybe remove?
x$html,
bodyEnd, # <=== Body ends here, maybe remove?
"</html>")
}
dt_html <- datatable_html(DT::datatable(iris))
# print (very large output):
cat(dt_html)
现在
dt_html
包含向量中的 html 段,并将依赖项复制到
{dir}/{libdir}
它应该是 Markdown 项目根目录下的文件夹。需要注意的几点: html 向量在
dt_html[6]
中具有依赖关系。 (可能必须包含在 Markdown 序言中?)并且 htmlscript 本身位于
dt_html[10]
带有
dt_html[9]
中的正文标签和
dt_html[11]
分别。
dt_html
中的 html 段应该以某种方式完成这项工作。
关于R Markdown : datable within collapsible section,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66670299/
这是我的代码片段:http://www.share-elm.com/sprout/53d242e2e4b07afa6f9834a2灵感来自 elm-lang.org 的 example . main
抱歉,如果这个问题有点基础,但互联网上的研究并没有得出任何合理的答案。我希望能够在我的网站上运行 markdown,类似于 github 所拥有的(编辑/预览设置)或实际上与 stackoverflo
我正在使用 markdown 编写文档,我正在使用 pandoc 将其导出为 PDF。在文档的末尾,我需要在 PDF 的打印副本上留出签名空间。 我试图找到如何绘制一条固定宽度的线,但到目前为止我只需
我已经搜索过谷歌和 SO,不知道 SO 是否是问这个的地方,但我想知道是否有标记可以为 Markdown 做某种类型的注释?我们在 Markdown 中为我们的项目做文档,并希望在不更改内容的情况下在
我想使用简单的文本编辑器和 Markdown 做类笔记。有没有办法标记文本元素以使其机器可读? 例如,我想将某些单词和短语标记为“定义”。然后,我可以运行某种脚本来显示单词及其相应的定义。 最佳答案
我有两个markdown文件:一个parent.md和child.md。 所以parent.md: # Main section ## sub-section 我想引用## sub-section中的
我需要在 Markdown 中创建一个类似嵌套的表,如下所示: 我怎样才能做到这一点? 最佳答案 @Waylan 是对的,您可以将 HTML(例如使用 Markdown 生成的表格)粘贴到 Markd
有没有办法在 Github markdown 的代码片段中链接表单? 例如:`I want THIS to be a link`哪里THIS看起来像 THIS . 最佳答案 我想通过 Markdown
我正在 Github 风格的 Markdown 中整理一些文档,并且我想整理一个有两行的表格。一种是简单的文本,另一种是 json 代码块。这是一个例子。 | Status | Response |
使用 GitHub 上“Markdown Cheatsheet ”中的表示例,您会得到以下结果: | Tables | Are | Cool | | -------
我对 Markdown 中的引号有疑问。当我有这样的事情时: text > quoted text > > deeper layer > > > even deeper
我正在寻找与 Markdown 中的多行代码功能等效的引号。对于代码块我可以方便地编写: ``` this is a code example ``` 有谁知道下面的事情是否可能? >>>
我想在 Markdown 中创建一个列表,但没有项目符号点。这可能吗? 到目前为止,我发现唯一推荐的方法是使用 HTML,我想避免使用 HTML。 最佳答案 这听起来似乎很明显,但是......您可以
我想编写一份编码标准规范文档,其中包含好和坏编码示例。每条规则都应该有一个编号、描述和示例。 例如,这是规则 1: # Rule 1 Description for rule 1. ## Good `
可以关注Marked library documentation并内联渲染一个 Markdown 字符串。这是一个有效的代码片段。 document.getElementById
据我所知,markdown 是 html 的“简化”版本。它易于使用和阅读。但我在创建输入表单时遇到了问题。 有人可以建议是否有任何方法可以在 Markdown 中添加 html 输入表单元素吗?我搜
如何在 Markdown 解析文档中包含小书签?是否有任何 Markdown 的“标签”基本上是说“不要解析这个”?? 例如,您可以有类似的内容: Hello 但是如果我尝试将其中的 JavaScri
可以关注Marked library documentation并内联渲染一个 Markdown 字符串。这是一个有效的代码片段。 document.getElementById
我想编写一个 R Markdown 文档,其中提供了如何编写 R Markdown 文档的代码示例。例如,我想在文档中展示如何将文本呈现为粗体。 `**this is bold**` will ren
我目前正在使用 GitHub 页面构建一个网站,并尝试利用一些 GitHub 风格的 Markdown 功能。特别隔离的代码块和表。 使用 redcarpet,我得到语法突出显示的围栏 block ,
我是一名优秀的程序员,十分优秀!