简体   繁体   English

寻找一种简单的方法将 profvis output 包含在 R 的 Markdown 文件中

[英]Looking for a simple way to include profvis output in a Markdown file in R

The title pretty much says it all.标题基本概括了所有内容。 I want to profile a function in R (with the profvis package) and display the output in an R Markdown file, without manually creating a screenshot and ideally with no additional packages except the ones that are loaded with profvis, eg htmlWidgets and htmltools. I want to profile a function in R (with the profvis package) and display the output in an R Markdown file, without manually creating a screenshot and ideally with no additional packages except the ones that are loaded with profvis, eg htmlWidgets and htmltools.

To be more specific I imagine something like:更具体地说,我想像:

library(profvis)
profvis_output <- profvis(rnorm(1e06))
htmlwidgets::saveWidget(profvis_output, "provis_output.html")

and then include the thereby created html file in Markdown.然后将由此创建的 html 文件包含在 Markdown 中。

I already tried我已经试过了

htmltools::includeHTML("profvis_output.html") 

in the Markdown file but that did not work.在 Markdown 文件中,但这不起作用。

NOTE: I also want it to be renderable to a PDF注意:我还希望它可以渲染到 PDF

This seems to work:这似乎有效:

---
title: "Untitled"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(profvis)    
```

## profvis

This is an R Markdown document using profvis.

```{r}
profvis({
  data(diamonds, package = "ggplot2")    
  plot(price ~ carat, data = diamonds)
  m <- lm(price ~ carat, data = diamonds)
  abline(m, col = "red")
})
```

在此处输入图像描述

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

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