简体   繁体   English

从 R DT 数据表创建独立的 HTML

[英]Creating stand-alone HTML from R DT Datatables

How can I save a datatable created using the DT package so that it can be copied and used by others who don't have R?如何保存使用datatable包创建的数据DT ,以便其他没有 R 的人可以复制和使用它? Is there a function to convert the datatable variable into texts of HTML that can be exported?是否有将数据datatable变量转换为可以导出的 HTML 文本的函数?

Use htmlwidgets::saveWidget() :使用htmlwidgets::saveWidget()

iris %>% DT::datatable()
result <- iris %>% DT::datatable()
htmlwidgets::saveWidget(result, "result.html")

The best way to do this is to generate a html-file using Rmarkdown, to use Rmarkdown with DT, see this thread .执行此操作的最佳方法是使用 Rmarkdown 生成一个 html 文件,要将 Rmarkdown 与 DT 一起使用,请参阅此线程

Render the rmd file with render from the rmarkdown package.使用 rmarkdown 包中的render rmd 文件。 You can also render directly from Rstudio, but in this case Rstudio creates a new Rsession for rendering and objects you defined will not be available.您也可以直接从 Rstudio 进行渲染,但在这种情况下,Rstudio 会创建一个新的 Rsession 用于渲染,您定义的对象将不可用。

Also possibly useful to share your data with people who don't use R:与不使用 R 的人共享数据也可能有用:

To export data.导出数据。 tables to html or latex tables there are the functions xtable from the package xtable and the function kable from the knitr package.表格到 html 或乳胶表格有xtable包中的 xtable 函数和 knitr 包中的kable函数。

To export to csv there are the write.csv , write.table , ... funcitons in the utils package.要导出到 csv,在 utils 包中有write.csvwrite.table ……函数。

To export to xlsx there are various funcitons in the packages xlsx and XLConnect.要导出到 xlsx,包 xlsx 和 XLConnect 中有各种功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM