我正在使用flexdashboard生成交互式树图。但是该图无法正确渲染。
我的代码和输出如下:
---
title: "flexdashboard: Shiny Embedding"
output:
flexdashboard::flex_dashboard:
social: menu
source_code: embed
runtime: shiny
---
```{r global, include=FALSE}
library(tidyverse)
library(highcharter)
library(treemap)
## generate a sample dataset
sample<-tbl_df(data.frame(c("City1","City2","City3","City1","City2","City3",
"City2","City3"),
c("A","B","C","D","D","A","A","B"),
c(12,14,15,12,12,14,8,10)))
colnames(sample)<-c("City","Country","Amount")
variable<-"City"
trmap<-function(variable)
{
d<- cbind(sample[,variable],sample[,"Amount"])
tm <- treemap(d, index = variable,
vSize = "Amount")
highchart() %>%
hc_title(text = paste("Treemap de", variable ),
style = list(fontSize = "15px")) %>%
hc_add_series_treemap(tm)
}
```
Column {.sidebar}
-------------------------------------------
```{r}
selectInput(inputId="variable",label="group by",choices=c("City","Country"))
```
Column
------------------------------------------
### Plot
```{r}
renderPlot(trmap(input$variable))
```
但是该图最初是动态的,因为当我将光标放在每个城市的框中时,它都会显示数量。
如何正确绘制图以获取显示数字的动态图?