我正在 Rstudio 上使用 FlexDashboard 构建仪表板,我想包含两个图表:
- 圆形包装
- 一棵可折叠的树
当我渲染 flexdashboard 时,两个图都消失了。如果我手动运行代码,一切正常,没有错误。如果我只包括一个情节,它就会出现!但是有两个,我得到一个空白页但没有错误。
这是一个可重现的示例,我在 R 3.6.3 上运行:
---
title: "Example"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
self_contained: true
---
<style>
.navbar, [data-toggle=tab], .navbar-brand {
background-color:#81BC00;
border-color:#81BC00;
color:white;
}
</style>
```{r setup, include=FALSE}
library(flexdashboard)
```
```{r include=FALSE}
# Circlepacker package
library(circlepackeR)
# devtools::install_github("jeromefroe/circlepackeR") # If needed
data <- data.frame(
root=rep("root", 15),
group=c(rep("group A",5), rep("group B",5), rep("group C",5)),
subgroup= rep(letters[1:5], each=3),
subsubgroup=rep(letters[1:3], 5),
value=sample(seq(1:15), 15)
)
# Change the format. This use the data.tree library. This library needs a column that looks like root/group/subgroup/..., so I build it
library(data.tree)
data$pathString <- paste("world", data$group, data$subgroup, data$subsubgroup, sep = "/")
population <- as.Node(data)
# Make the plot
#circlepackeR(population, size = "value")
# You can custom the minimum and maximum value of the color range.
p <- circlepackeR(population, size = "value", color_min = "hsl(56,80%,80%)", color_max = "hsl(341,30%,40%)")
```
```{r include=FALSE}
library(collapsibleTree)
org <- data.frame(
Manager = c(
NA, "Ana", "Ana", "Bill", "Bill", "Bill", "Claudette", "Claudette", "Danny",
"Fred", "Fred", "Grace", "Larry", "Larry", "Nicholas", "Nicholas"
),
Employee = c(
"Ana", "Bill", "Larry", "Claudette", "Danny", "Erika", "Fred", "Grace",
"Henri", "Ida", "Joaquin", "Kate", "Mindy", "Nicholas", "Odette", "Peter"
),
Title = c(
"President", "VP Operations", "VP Finance", "Director", "Director", "Scientist",
"Manager", "Manager", "Jr Scientist", "Operator", "Operator", "Associate",
"Analyst", "Director", "Accountant", "Accountant"
)
)
p2 <- collapsibleTree(org, c("Manager", "Employee"), collapsed = FALSE)
```
### <b>How to read this chart </b> {data-width=100}
Description
### <b>Circular Packing </b> {data-width=500}
```{r}
p
```
### <b>Collapsible Tree</b> {data-width=400}
```{r}
p2
```