在Flexdashboard中使用Highchart渲染交互式树图

时间:2019-01-09 16:01:51

标签: r highcharts treemap flexdashboard

我正在使用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))
```

此代码的输出是下一个仪表板:enter image description here

但是该图最初是动态的,因为当我将光标放在每个城市的框中时,它都会显示数量。

enter image description here

如何正确绘制图以获取显示数字的动态图?

0 个答案:

没有答案