使用选项卡将VisNetwork添加到RMarkdown(可视化未显示)

时间:2016-10-11 14:17:41

标签: r tabs igraph r-markdown htmlwidgets

我想创建一个RMarkdown html文档。当我创建一个rmarkdown文档时,顶部有选项卡,但可视化文件没有显示在第二个选项卡中。虽然当我没有标签时,可视化很好。如何在第二个选项卡中包含可视化?

下面的可重现代码:

---
title: "StackOverflow Example"
output: html_document
---

## Demand Team Analytics {.tabset}

### Overview

```{r}
summary(cars)
```

### Prediction Analytics

```{r, message = FALSE, include = FALSE, warning=FALSE}
library(igraph)
library(visNetwork)
B = matrix( 
c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 47, 3, 0, 3, 0, 1, 10, 13, 5,
0, 3, 19, 0, 1, 0, 1, 7, 3, 1,
0, 0, 0, 3, 0, 0, 0, 0, 0, 0,
0, 3, 1, 0, 32, 0, 0, 3, 2, 1,
0, 0, 0, 0, 0, 2, 0, 0, 0, 0,
0, 1, 1, 0, 0, 0, 2, 1, 1, 0,
0, 10, 7, 0, 3, 0, 1, 90, 12, 4, 
0, 13, 3, 0, 2, 0, 1, 12, 52, 4, 
0, 5, 1, 0, 1, 0, 0, 4, 4, 18), 
nrow=10, 
ncol=10)
colnames(B) <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")
rownames(B) <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")

g96e = t(B) %*% B

i96e = graph.adjacency(g96e, mode = "undirected", weighted = TRUE, diag=FALSE)

V(i96e)$label = V(i96e)$name
V(i96e)$label.color = rgb(0,0,.2,.8)
V(i96e)$label.cex = .1
V(i96e)$size = 2
V(i96e)$color = rgb(0,0,1,.5)
V(i96e)$frame.color = V(i96e)$color
fc<-fastgreedy.community(i96e, merges=TRUE, modularity=TRUE,
                 membership=TRUE, weights=E(i96e)$weight)
colors <- rainbow(max(membership(fc)))

col = c("#80FF00FF", "#FF0000FF", "#FF0000FF", "#00FFFFFF",
"#FF0000FF", "#8000FFFF", "#FF0000FF", "#FF0000FF",
"#FF0000FF", "#FF0000FF")
i96e <- set.vertex.attribute(i96e, name = "group",value = col)
i96e = graph.adjacency(g96e, mode = "undirected", weighted = TRUE, diag=FALSE)
i96e <- set.vertex.attribute(i96e, name = "group",value = col)
```

```{r, echo=FALSE}
visIgraph(i96e, idToLabel = F, layout = "layout_nicely") %>%
  visOptions(highlightNearest = TRUE, selectedBy = "group")
```

enter image description here

当我删除## Demand Team Analytics旁边的{.tabset}文字时,它可以正常运行,但没有标签。

这是没有标签的情况:

enter image description here

任何帮助都会很棒,谢谢!

0 个答案:

没有答案