renderBarChart: Render the Bar Chart Plotted by ECharts into Shiny...

Description Usage Arguments Note Author(s) Examples

Description

renderBarChart() function helps render the bar chart into Shiny application.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
renderBarChart(div_id, data, theme,
               stack_plot = FALSE, direction = "horizontal",
               grid_left,grid_right, grid_top, grid_bottom,
               show.legend = TRUE, show.tools = TRUE,
               font.size.legend = 12,
               font.size.axis.x = 12, font.size.axis.y = 12,
               axis.x.name = NULL, axis.y.name = NULL,
               rotate.axis.x = 0, rotate.axis.y = 0,
               bar.max.width = NULL,
               animation = TRUE,
               hyperlinks = NULL,
               running_in_shiny)

Arguments

div_id

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

data

The data used for the plotting. It should be a data.frame. Each column of the data.frame is one category, and each row is one observation (like one timepoint).

theme

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

stack_plot

Whether do stack bar chart. The default value is FALSE.

direction

The direction of the bar chart. Valid values include "vertical" and "horizontal". Default value is "horizontal".

grid_left

Distance between grid component and the left side of the container. Default value is "3%".

grid_right

Distance between grid component and the right side of the container. Default value is "4%".

grid_top

Distance between grid component and the top side of the container. Default value is "16%".

grid_bottom

Distance between grid component and the bottom side of the container. Default value is "3%".

show.legend

If display the legends. The default value is TRUE.

show.tools

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

font.size.legend

The font size of legend bar. The default value is 12.

font.size.axis.x

The font size of the labels on X axis. The default value is 12.

font.size.axis.y

The font size of the labels on Y axis. The default value is 12.

axis.x.name

The name of X axis. The default value is NULL.

axis.y.name

The name of Y axis. The default value is NULL.

rotate.axis.x

The rotation degree of labels on X axis. The default value is 0.

rotate.axis.y

The rotation degree of labels on Y axis. The default value is 0.

bar.max.width

The maximum width of the bar. The default value is NULL, in which case the bar width and maximum width will be automatically adjusted.

Users can also assign a numeric value to it, to customize the maximum bar width. If the width is too big or invalid value (like a character string), it will be automatically adjusted too.

animation

Whether display the chart with animation. The default value is TRUE.

hyperlinks

Vector. Users can link each element in the chart to a hyperlink (URL like http://***.com). Please note the length of the "hyperlinks" vector should be the same to the number of rows in the data given.

Note that if hyperlinks are available, the fonts in the pop-up window will be in skyblue color and italic style.

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
if (interactive()) {
  library(shiny)
  library(ECharts2Shiny)

  # Prepare sample data for plotting --------------------------
  dat <- data.frame(c(1, 2, 3),
                    c(2, 4, 6))
  names(dat) <- c("Type-A", "Type-B")
  row.names(dat) <- c("Time-1", "Time-2", "Time-3")

  # Server function -------------------------------------------
  server <- function(input, output) {
    # Call functions from ECharts2Shiny to render charts
    renderBarChart(div_id = "test", grid_left = '1%', direction = "vertical",
                   data = dat)
  }

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

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

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

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