在RMarkdown中创建图并编织为HTML的功能不起作用 [英] Function to create plot and knit to HTML in RMarkdown not working
问题描述
我在这个问题上陷入困境.我在r markdown文档中有一个功能.该函数采用案例编号"作为参数.变量,该变量用于过滤某些数据帧,生成图并将其输出到编织的html文档中.这是基本概念:
I'm stuck on this problem. I have a function in a r markdown document. The function takes a "case number" variable, which is used to filter some data frames, produce a plot, and output the plot to a knit html document. Here's the basic idea:
---
title: "Plot"
output:
html_document:
toc: true
toc_float: true
toc_depth: 2
---
```{r echo=FALSE, results='hide',message=FALSE,warning=FALSE}
library(dplyr)
library(ggplot2)
library(scales)
library(lubridate)
library(plotly)
library(vistime)
```
```{r echo = FALSE, warning=FALSE, fig.align='CENTER', fig.width=10, fig.height=5}
data <- read.csv(text="event,group,start,end,color
Phase 1,Project,2016-12-22,2016-12-23,#c8e6c9
Phase 2,Project,2016-12-23,2016-12-29,#a5d6a7
Phase 3,Project,2016-12-29,2017-01-06,#fb8c00
Phase 4,Project,2017-01-06,2017-02-02,#DD4B39
Room 334,Team 1,2016-12-22,2016-12-28,#DEEBF7
Room 335,Team 1,2016-12-28,2017-01-05,#C6DBEF
Room 335,Team 1,2017-01-05,2017-01-23,#9ECAE1
Group 1,Team 2,2016-12-22,2016-12-28,#E5F5E0
Group 2,Team 2,2016-12-28,2017-01-23,#C7E9C0
3-200,category 1,2016-12-25,2016-12-25,#1565c0
3-330,category 1,2016-12-25,2016-12-25,#1565c0
3-223,category 1,2016-12-28,2016-12-28,#1565c0
3-225,category 1,2016-12-28,2016-12-28,#1565c0
3-226,category 1,2016-12-28,2016-12-28,#1565c0
3-226,category 1,2017-01-19,2017-01-19,#1565c0
3-330,category 1,2017-01-19,2017-01-19,#1565c0
1-217.0,category 2,2016-12-27,2016-12-27,#90caf9
4-399.7,moon rising,2017-01-13,2017-01-13,#f44336
8-831.0,sundowner drink,2017-01-17,2017-01-17,#8d6e63
9-984.1,birthday party,2016-12-22,2016-12-22,#90a4ae
F01.9,Meetings,2016-12-26,2016-12-26,#e8a735
Z71,Meetings,2017-01-12,2017-01-12,#e8a735
B95.7,Meetings,2017-01-15,2017-01-15,#e8a735
T82.7,Meetings,2017-01-15,2017-01-15,#e8a735")
data <- as.data.frame(data)
#event_id <- "category 1"
build_plot <- function(event_id) {
data.filtered <- data%>%
filter(group==event_id)
p <- vistime(data.filtered)
pb <- plotly_build(p)
pb #Display plot
rmarkdown::render(input = "stack_overflow_example.Rmd",
output_format = "html_document",
output_file = 'stack_overflow_example.html',
output_dir = "//mydir/myfolder")
}
build_plot("category 1")
```
我收到此错误,并且没有文档输出:
I'm getting this error, and no document is output:
Error in sink(con, split = debug) : sink stack is full
任何帮助表示赞赏.
推荐答案
在文档上运行render
与将html编织在一起的功能相同.这包括运行文档中的所有R代码.
Running render
on a document does the same thing as knit to html. That includes running all the R code in the document.
但是您不应该在文档本身中放入render
-您创建了一个递归循环,因为您在文档上调用了render,从而在文档上运行了代码,在文档上调用了render,然后在文档上运行了render文件中的代码....
But you shouldn't put render
in the document itself - you've created a recursive loop because you call render on the document, which runs the code on the document, which calls render on the document, which runs the code in the document....
从文档中删除render
调用,而不是将其放在单独的R脚本中.然后,运行该脚本将呈现文档.
Remove the render
call from your document, instead put it in a separate R script. Then, running that script will render the document.
这篇关于在RMarkdown中创建图并编织为HTML的功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!