Learn R Programming

ECharts2Shiny (version 0.2.13)

renderPieChart: Render the Pie Chart Plotted by ECharts into Shiny Application

Description

renderPieChart() function helps render the pie chart into Shiny application.

Usage

renderPieChart(div_id, data,
               theme = 'default', radius, center_x,center_y,
               show.label = TRUE,
               show.legend = TRUE, show.tools = TRUE,
               font.size.legend= 12,
               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 either a vector or a data.frame.

If it's a vector, it should be made up of all the elements you want to count and plot, like c("a", "a", "b", "a", "b", "c").

If it's a data.frame, the data must be made up of only two columns, "name" and "value". The "value" column must be numeric or integer.

theme

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

radius

The radius of the pie chart. The default value is "75%".

center_x

The position of the center of the pie chart (x axis). Default value is "50%".

center_y

The position of the center of the pie chart (y axis). Default value is "50%".

show.label

Whether display the leble for the pie chart. The default value is TRUE.

show.legend

Whether display the legends. The default value is TRUE.

show.tools

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

font.size.legend

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

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 this is only supported when the data is in data.frame format, and 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.

Examples

Run this code
# NOT RUN {
if (interactive()) {
  library(shiny)
  library(ECharts2Shiny)


  dat <- c(rep("Type-A", 8),
             rep("Type-B", 5),
             rep("Type-C", 1))


  # Server function -------------------------------------------
  server <- function(input, output) {
    renderPieChart(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:50%;height:400px;"),
    deliverChart(div_id = "test")
  )

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

# }

Run the code above in your browser using DataLab