renderTreeMap: Render Interactive Tree Map into Shiny Application

Description Usage Arguments Note Author(s) Examples

Description

renderTreeMap() function helps render interactive tree map chart into Shiny application.

Usage

1
2
3
4
5
6
7
renderTreeMap(div_id,
              data,
              name = "Main",
              leafDepth = 2,
              theme = "default",
              show.tools = TRUE,
              running_in_shiny = TRUE)

Arguments

div_id

The division id users specified for this chart. The division will be specified in ui.R.

data

The data used for tree map. Not like other charts, here we need to use JSON data for the tree map charts, since there may be nested data which can be handled by JSON much easilier (please check 'example').

name

The name of the tree map chart.

leafDepth

It determines when the 'drill down' feature will start to work.

This is for mainly nested data, like we may ave categories 'A-1' and 'A-2' under 'A', and furtherly we have 'A-1-1' and 'A-1-2' under 'A-1'.

The value of this argument must be integer and bigger than 0 (float value will be converted to its ceiling value automatically). The default value is 2.

theme

Which ECharts theme to use. Valid values include "default", "roma", "infographic", "macarons", "vintage", "shine", "caravan", "dark-digerati", "jazz", and "london".

show.tools

If display the tool bar. The default value is TRUE.

running_in_shiny

If we're actually running this in a Shiny library, or we're simply doing testing. Default valus is "TRUE". If "FALSE", the function will print what it's supposed to evaluate.

Note

Users need to state the division for the chart first, with tags$div() function of Shiny packages. Please note that the division id must keep unique (duplicated division id will cause error).

Author(s)

Xiaodong DENG

(ECharts library is authored by Baidu team)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
if (interactive()) {
    library(shiny)
    library(ECharts2Shiny)

    # Prepare sample data for plotting --------------------------
    dat <- "[{name: 'A',
              value: 6,
              children: [
                  {
                  name: 'A-1',
                  value: 6,
                  children:[
                  {
                  name: 'A-1-1',
                  value: 6
                  },
                  {
                  name: 'A-1-2',
                  value: 2
                  }
                  ]
                  },
                  {
                  name: 'A-2',
                  value: 3
                  }
              ]
            },
            {
              name: 'B',
              value: 6,
              children: [
                  {name : 'B-1',
                  value:10
                  },
                  {
                  name:'B-2',
                  value:2
                  }
              ]
            },
            {
              name: 'C',
              value: 4
            }]"

    # Server function -------------------------------------------
    server <- function(input, output) {
      # Call functions from ECharts2Shiny to render charts
      renderTreeMap(div_id = "test",
                    data = dat)
        }

    # UI layout -------------------------------------------------
    ui <- fluidPage(
      # We MUST load the ECharts javascript library in advance
      loadEChartsLibrary(),

      tags$div(id="test", style="width:100%;height:500px;"),
      deliverChart(div_id = "test")
    )

    # Run the application --------------------------------------
    shinyApp(ui = ui, server = server)

}

ECharts2Shiny documentation built on May 2, 2019, 8:57 a.m.