Rahul Anand
Rahul Anand

Reputation: 53

Interactive Treemap with d3treeR not rendering in Shiny

I am a newbie to Shiny and I am trying to use the d3TreeR HTML Widget to display an interactive treemap

I used the following code and it ran perfectly in R:

library(readxl)
budget_map <- read_excel(path = 'Trader Dashboard Data Prep Sample.xlsx',sheet='v2',col_names = TRUE)
library(treemap)
budget_treemap <- treemap(budget_map,index=c("Sales Agency","Agency","Advertiser"),vSize="Booked Revenue Net",vColor="Sales Agency",palette = "Set1",type="categorical",title="Australia Budget Map",fontsize.title=22)
library(d3treeR)
d3tree2(budget_treemap)

I'm trying to get it to render in Shiny and am using the following code:

library(shiny)
library(readxl)
library(treemap)
library(htmlwidgets)
library(data.tree)
library(d3treeR)
budget_map <- read_excel(path = 'C:/Users/rahul/Desktop/30k foot view/Trader Dashboard Data Prep Sample.xlsx',sheet='v2',col_names = TRUE)
budget_treemap <- treemap(budget_map,index=c("Sales Agency","Agency","Advertiser"),vSize="Booked Revenue Net",vColor="Sales Agency",palette = "Set1",type="categorical")

ui <- fluidPage(
  d3tree2Output("au_budget_map")
)


server <- function(input,output){
    output$au_budget_map <- renderD3tree2({budget_treemap})
}

shinyApp(ui = ui, server = server)

Attaching sample data to make it reproducible: https://drive.google.com/open?id=0B2LJXtBTsuhhcnZJeXI3T0kwYW8 I know I might be missing something very evident - but am not able to spot it! Any help would be really great! Thanks!

Upvotes: 5

Views: 3283

Answers (1)

HubertL
HubertL

Reputation: 19544

renderD3tree2 accepts result of d3tree2 as input :

output$au_budget_map <- renderD3tree2({d3tree2(budget_treemap)})

Upvotes: 4

Related Questions