我无法在R Markdown中显示情节 在R脚本中运行以下代码可以正常工作并生成图表。 在R Markdown文档中运行相同的代码不会。
感谢@aosmith在this post中对图表进行分组。
---
title: "TestingIssue"
author: "John"
date: "August 18, 2015"
output: html_document
---
```{r, results='asis'}
# Load visualization & manipulation libraries
library(ggvis)
library(dplyr)
library(knitr) # added this per aosmith suggestion
# Build DF
dailyCaloriesDF <- structure(list(Name = c("Amy", "Amy", "Amy", "Amy", "Amy", "Amy",
"Amy", "Amy", "Amy", "Sue", "Sue", "Sue", "Sue", "Sue", "Sue",
"Sue", "Sue", "Sue", "Jim", "Jim", "Jim", "Jim", "Jim", "Jim",
"Jim", "Jim", "Jim"),
Date = c("1/1/2015", "1/2/2015", "1/3/2015",
"1/4/2015", "1/5/2015", "1/6/2015", "1/7/2015", "1/8/2015", "1/9/2015",
"1/1/2015", "1/2/2015", "1/3/2015", "1/4/2015", "1/5/2015", "1/6/2015",
"1/7/2015", "1/8/2015", "1/9/2015", "1/1/2015", "1/2/2015", "1/3/2015",
"1/4/2015", "1/5/2015", "1/6/2015", "1/7/2015", "1/8/2015", "1/9/2015"),
Calories = c(1700L, 1650L, 1600L, 1550L, 1500L, 1450L, 1400L,
1350L, 1300L, 2000L, 1950L, 1900L, 1850L, 1800L, 1750L, 1700L,
1650L, 1600L, 1800L, 1750L, 1700L, 1650L, 1600L, 1550L, 1500L,
1450L, 1400L)),
.Names = c("Name", "Date", "Calories"),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA, -27L))
# Build function
makeCharts = function(dat) {
dat %>% ggvis(~Date, ~Calories)
}
# Execute for each group by name
allplots2 = dailyCaloriesDF %>%
group_by(Name) %>%
do(plots = makeCharts(.))
# Print plots - This won't work in markdown, but will work in script
allplots2$plots
# New code, per aosmith suggestion
data(mtcars)
plots <- lapply(1:5, function(x){
ggvis(mtcars, ~cyl, ~mpg) %>% layer_points() %>% knit_print
})
html <- paste0(lapply(plots, unclass), collapse = "\n")
asis_output(html, ggvis_dependencies(absolute = TRUE, in_shiny = FALSE))
```
当我在markdown文档中运行该代码时,我只是在生成的文档中获得控制台输出。
[[1]]
[[2]]
[[3]]
...
新代码提供了此错误消息:
Quitting from lines 9-53 (testOutput.Rmd)
Error in structure(x, class = "knit_asis", knit_meta = meta, knit_cacheable = cacheable) :
could not find function "ggvis_dependencies"
Calls: <Anonymous> ... withVisible -> eval -> eval -> asis_output -> structure