我正在尝试使用rmarkdown创建一个文档,其中包括来自rCharts包和使用htmlwidgets中的DT库的数据表格。但是由于某种原因,我无法同时显示它们。
---
title: "Untitled"
output: html_document
---
```{r, echo=FALSE}
library(DT)
library(rCharts)
df<-data.frame(Name=c("a","Z","h","k","j"),Value=(sample(10^7,5)))
datatable(df, filter = 'top', options = list(
pageLength = 10,iDisplaylength=10, autoWidth = TRUE
))
```
```{r, message=FALSE, echo=FALSE, results='asis'}
df<-data.frame(label=c("One","Two","Three"),valuea=c(1,2,3),
othera=c(10,11,12),stringsAsFactors = FALSE)
p1 <- nPlot(valuea~ label, data = df, type = 'pieChart')
#Different options I tried
p1$print('inline', include_assets = TRUE, cdn = FALSE)
#p1$show('inline', include_assets = TRUE, cdn = FALSE)
#p1$print('inline', include_assets = TRUE)
#p1$show('inline', include_assets = TRUE)
#These provide an error
#p1$print('inline', include_assets = TRUE, cdn = TRUE)
#p1$show('inline', include_assets = TRUE, cdn = TRUE)
```
注释的行是我尝试过的事情。
注意:如果p1$print('inline', include_assets = TRUE, cdn = FALSE)
被注释掉,则数据表格可以正常显示。
注意 II:我知道可以使用函数与iframe结合使用,但我想在图表中使用内联方式。
htmlwidgets
比使用rCharts
要更好。对于饼图,有几个不错的选择。 - timelyportfolio