将 R 表导出为 HTML

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3438226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:02:43  来源:igfitidea点击:

Exporting R tables to HTML

htmlrexport

提问by David B

Is there a way to easily export R tables to a simple HTML page?

有没有办法轻松地将 R 表导出到简单的 HTML 页面?

采纳答案by nullglob

The xtablefunction in the xtablepackage can export R tables to HTML tables. This blog entrydescribes how you can create HTML pages from Sweave documents.

包中的xtable函数xtable可以将 R 表导出为 HTML 表。此博客条目介绍了如何从 Sweave 文档创建 HTML 页面。

回答by LyzandeR

It might be worth mentioning that there has been a new package specifically designed to convert (and style with css) data.frames (or tables) into HTML tables in an easy and intuitive way. It is called tableHTML. You can see a simple example below:

值得一提的是,有一个新包专门设计用于以简单直观的方式将 data.frames(或表格)转换(并使用 css 样式)转换为 HTML 表格。它被称为tableHTML。您可以在下面看到一个简单的示例:

library(tableHTML)
#create an html table 
tableHTML(mtcars)

#and to export in a file
write_tableHTML(tableHTML(mtcars), file = 'myfile.html')

You can see a detailed tutorial hereas well.

您也可以在此处查看详细教程。

回答by radek

Apart from xtablementioned by @nullglob there are three more packages that might come handy here:

除了xtable@nullglob 提到的之外,这里还有三个可能派上用场的包:

回答by sbha

The grammar of tables package gtis also an option.

表包gt的语法也是一个选项。

Here's the examplefrom the docs for generating a HTML table:

这是文档中用于生成 HTML 表格的示例

library(gt)

tab_html <-
  gtcars %>%
  dplyr::select(mfr, model, msrp) %>%
  dplyr::slice(1:5) %>%
  gt() %>%
  tab_header(
    title = md("Data listing from **gtcars**"),
    subtitle = md("`gtcars` is an R dataset")
  ) %>%
  as_raw_html()