package ‘echarts2shiny’ · package ‘echarts2shiny ... these charts will be gener-ated by...

25
Package ‘ECharts2Shiny’ December 11, 2017 Type Package Title Embedding Interactive Charts Generated with ECharts Library into Shiny Applications Imports shiny,jsonlite Version 0.2.13 Date 2017-12-11 Maintainer Xiaodong Deng <[email protected]> Description Embed interactive charts to their Shiny applications. These charts will be gener- ated by ECharts library developed by Baidu (<http://echarts.baidu.com/>). Current version sup- ports line chart, bar chart, pie chart, scat- ter plot, gauge, word cloud, radar chart, tree map, and heat map. URL https://github.com/XD-DENG/ECharts2Shiny BugReports https://github.com/XD-DENG/ECharts2Shiny/issues License GPL-2 LazyData TRUE Suggests knitr, rmarkdown VignetteBuilder knitr NeedsCompilation no Author Xiaodong Deng [aut, cre], Hao Zhu [ctr], Yiheng Li [ctr], Janet Wagner [ctr], ChinYong Lim [ctr] Repository CRAN Date/Publication 2017-12-11 14:50:23 UTC R topics documented: deliverChart ......................................... 2 loadEChartsLibrary ..................................... 3 1

Upload: doduong

Post on 26-Sep-2018

243 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

Package ‘ECharts2Shiny’December 11, 2017

Type Package

Title Embedding Interactive Charts Generated with ECharts Library intoShiny Applications

Imports shiny,jsonlite

Version 0.2.13

Date 2017-12-11

Maintainer Xiaodong Deng <[email protected]>

Description Embed interactive charts to their Shiny applications. These charts will be gener-ated by ECharts library developed by Baidu (<http://echarts.baidu.com/>). Current version sup-ports line chart, bar chart, pie chart, scat-ter plot, gauge, word cloud, radar chart, tree map, and heat map.

URL https://github.com/XD-DENG/ECharts2Shiny

BugReports https://github.com/XD-DENG/ECharts2Shiny/issues

License GPL-2

LazyData TRUE

Suggests knitr, rmarkdown

VignetteBuilder knitr

NeedsCompilation no

Author Xiaodong Deng [aut, cre],Hao Zhu [ctr],Yiheng Li [ctr],Janet Wagner [ctr],ChinYong Lim [ctr]

Repository CRAN

Date/Publication 2017-12-11 14:50:23 UTC

R topics documented:deliverChart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2loadEChartsLibrary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1

Page 2: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

2 deliverChart

loadEChartsTheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4renderBarChart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5renderGauge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8renderHeatMap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9renderLineChart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11renderPieChart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14renderRadarChart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16renderScatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17renderTreeMap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20renderWordcloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Index 25

deliverChart Deliver the Chart in the UI Component of Shiny Applications

Description

This function helps deliver the charts plotted by ECharts into Shiny applications.

Usage

deliverChart(div_id, running_in_shiny = TRUE)

Arguments

div_id The id of the div which you need to specify first with tags$div() function ofShiny.

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 supposedto evaluate.

Details

This will help us deliver the interactive charts. At the back-end, everything is donw by Javascript.

Note

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

Author(s)

Xiaodong DENG

(ECharts library is authored by Baidu team)

Page 3: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

loadEChartsLibrary 3

Examples

if (interactive()) {library(shiny)library(ECharts2Shiny)

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

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

}

# UI layout -------------------------------------------------ui <- fluidPage(

# We MUST load the ECharts javascript library in advanceloadEChartsLibrary(),

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

)

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

}

loadEChartsLibrary Load the Javascript Library File of ECharts to the Shiny Application

Description

This function will help load the Javascript library file of ECharts to the current shiny project. Thisis mandatory before we can plot with ECharts in Shiny applications.

Usage

loadEChartsLibrary()

Author(s)

Xiaodong DENG

(ECharts library is authored by Baidu team)

Page 4: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

4 loadEChartsTheme

Examples

if (interactive()) {library(shiny)library(ECharts2Shiny)

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

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

data = dat)}

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

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

)

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

}

loadEChartsTheme Load the Theme File of ECharts to the Shiny Application

Description

This function will help load the theme file of ECharts into the current Shiny application. This is notmandatory for the basic use of this package. But if users want to try different theme, they need toload the corresponding theme file.

Usage

loadEChartsTheme(theme)

Arguments

theme The theme file users want to use. The valid values include "infographic", "mac-arons", "roma", "shine", and "vintage".

Page 5: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

renderBarChart 5

Details

Users can simply use the default theme. But if they want to try different theme of the charts, theyneed to load the corresponding JS file.The theme files are not loaded automatically so that we don’thave to include unnecessary files into the Shiny applications (you only include what you need).

Author(s)

Xiaodong DENG

(ECharts library is authored by Baidu team)

Examples

if (interactive()) {library(shiny)library(ECharts2Shiny)

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

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

data = dat, theme = "vintage")}

# UI layout -------------------------------------------------ui <- fluidPage(# We MUST load the ECharts javascript library in advanceloadEChartsLibrary(),loadEChartsTheme("vintage"),

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

)

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

}

renderBarChart Render the Bar Chart Plotted by ECharts into Shiny Application

Page 6: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

6 renderBarChart

Description

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

Usage

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 inui.R.

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

theme Which ECharts theme to use. Valid values include "default", "roma", "info-graphic", "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. Defaultvalue is "3%".

grid_right Distance between grid component and the right side of the container. Defaultvalue is "4%".

grid_top Distance between grid component and the top side of the container. Defaultvalue is "16%".

grid_bottom Distance between grid component and the bottom side of the container. Defaultvalue 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.

Page 7: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

renderBarChart 7

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 thebar width and maximum width will be automatically adjusted.Users can also assign a numeric value to it, to customize the maximum barwidth. If the width is too big or invalid value (like a character string), it will beautomatically 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 likehttp://***.com). Please note the length of the "hyperlinks" vector should bethe 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 inskyblue 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 supposedto evaluate.

Note

Users need to state the division for the chart first, with tags$div() function of Shiny packages. Pleasenote 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

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) {

Page 8: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

8 renderGauge

# Call functions from ECharts2Shiny to render chartsrenderBarChart(div_id = "test", grid_left = '1%', direction = "vertical",

data = dat)}

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

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

)

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

}

renderGauge Render the Gauge Chart Plotted by ECharts into Shiny Application

Description

renderGauge() function helps render the gauge chart into Shiny application.

Usage

renderGauge(div_id, theme = "default", gauge_name, rate,show.tools = TRUE,animation = TRUE,running_in_shiny = TRUE)

Arguments

div_id The division id users specified for this chart. The division will be specified inui.R.

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

gauge_name The title to show on the gauge. It can not be ignored.rate As the gauge helps show some kind of rate, users need to give this rate value. It

must be numerical or integer values.show.tools If display the tool bar. The default value is TRUE.animation Whether display the chart with animation. 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 supposedto evaluate.

Page 9: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

renderHeatMap 9

Note

Users need to state the division for the chart first, with tags$div() function of Shiny packages. Pleasenote 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

if (interactive()) {library(shiny)library(ECharts2Shiny)

# Server function -------------------------------------------server <- function(input, output) {# Call functions from ECharts2Shiny to render chartsrenderGauge(div_id = "test",rate = 99, gauge_name = "Finish Rate")

}

# UI layout -------------------------------------------------ui <- fluidPage(

# We MUST load the ECharts javascript library in advanceloadEChartsLibrary(),

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

)

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

}

renderHeatMap Render Heat Map Plotted by ECharts into Shiny Applications

Description

renderHeatMap() function helps render heat map charts into Shiny applications.

Usage

renderHeatMap(div_id, data,theme = "default",show.tools = TRUE,

grid_left = "3%", grid_right = "4%", grid_top = "16%", grid_bottom = "3%",running_in_shiny = TRUE)

Page 10: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

10 renderHeatMap

Arguments

div_id The division id users specified for this chart. The division will be specified inui.R.

data The data input must be a matrix containing numeric or integer values. Users canchoose to have or not have row names or columns names.From version 2.10, the data input (matrix) must be with row names and columnnames.

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

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

grid_left Distance between grid component and the left side of the container. Defaultvalue is "3%".

grid_right Distance between grid component and the right side of the container. Defaultvalue is "4%".

grid_top Distance between grid component and the top side of the container. Defaultvalue is "16%".

grid_bottom Distance between grid component and the bottom side of the container. Defaultvalue is "3%".

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 supposedto evaluate.

Note

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

Author(s)

Xiaodong DENG

(ECharts library is authored by Baidu team)

References

https://github.com/ecomfe/echarts-wordcloud

Examples

if (interactive()) {library(shiny)library(ECharts2Shiny)

# Server function -------------------------------------------

Page 11: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

renderLineChart 11

server <- function(input, output) {dat <- volcanorow.names(dat) <- 1:dim(dat)[1]colnames(dat) <- 1:dim(dat)[2]

renderHeatMap(div_id = "test",data = dat)

}

# UI layout -------------------------------------------------ui <- fluidPage(

# We MUST load the ECharts javascript library in advanceloadEChartsLibrary(),

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

)

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

}

renderLineChart Render the Line Chart Plotted by ECharts into Shiny Application

Description

renderLineChart() function helps render the line chart into Shiny application.

Usage

renderLineChart(div_id, data, theme = "default",line.width = 2, line.type = "solid",point.size = 5, point.type = "emptyCircle",stack_plot = FALSE, step = "null",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,show.slider.axis.x = FALSE, show.slider.axis.y = FALSE,animation = TRUE,

grid_left = "3%", grid_right = "4%", grid_top = "16%", grid_bottom = "3%",running_in_shiny = TRUE)

Page 12: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

12 renderLineChart

Arguments

div_id The division id users specified for this chart. The division will be specified inui.R.

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

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

line.width This is to help set the width of the lines.The value should be either numeric or integer. The default value is 2.Its length should be either one or the same as the number of categories in thedata (the number of columns in the data).

line.type The type of the lines.The value can be "solid", "dashed", or "dotted". The default value is "solid".Its length should be either one or the same as the number of categories in thedata (the number of columns in the data).

point.size This argument helps set the size of points in the scatter plots.The value should be either numeric or integer. The default value is 5.Its length should be either one or the same as the number of categories in thedata (the number of columns in the data).

point.type The shape of the points in scatter plots.Valid values include ’emptyCircle’, ’circle’, ’rect’, ’roundRect’, ’triangle’, ’dia-mond’, ’pin’, ’arrow’. The default value is ’emptyCircle’.Its length should be either one or the same as the number of categories in thedata (the number of columns in the data).

stack_plot Whether do stack line chart. The default value is FALSE.

step This argument helps plot step line charts. The default value is "null", i.e., non-step line chart.If users want step line chart, they can choose "start", "middle", or "end" to de-termine the turning point positions in the step line charts.

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.

Page 13: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

renderLineChart 13

show.slider.axis.x

Whether display slider on X axis. The default value is FALSE.show.slider.axis.y

Whether display slider on Y axis. The default value is FALSE.

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

grid_left Distance between grid component and the left side of the container. Defaultvalue is "3%".

grid_right Distance between grid component and the right side of the container. Defaultvalue is "4%".

grid_top Distance between grid component and the top side of the container. Defaultvalue is "16%".

grid_bottom Distance between grid component and the bottom side of the container. Defaultvalue is "3%".

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 supposedto evaluate.

Note

Users need to state the division for the chart first, with tags$div() function of Shiny packages. Pleasenote 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

if (interactive()) {library(shiny)library(ECharts2Shiny)

dat <- data.frame(c(1, 2, 3, 1),c(2, 4, 6, 6),c(3, 2, 7, 5))

names(dat) <- c("Type-A", "Type-B", "Type-C")row.names(dat) <- c("Time-1", "Time-2", "Time-3", "Time-4")

# Server function -------------------------------------------server <- function(input, output) {

renderLineChart(div_id = "test",data = dat)

}

# UI layout -------------------------------------------------ui <- fluidPage(

Page 14: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

14 renderPieChart

# We MUST load the ECharts javascript library in advanceloadEChartsLibrary(),

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

)

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

}

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 inui.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 andplot, 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", "info-graphic", "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.

Page 15: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

renderPieChart 15

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 likehttp://***.com). Please note this is only supported when the data is in data.frameformat, and the length of the "hyperlinks" vector should be the same to the num-ber of rows in the data given.Note that if hyperlinks are available, the fonts in the pop-up window will be inskyblue 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 supposedto evaluate.

Note

Users need to state the division for the chart first, with tags$div() function of Shiny packages. Pleasenote 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

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 advanceloadEChartsLibrary(),

Page 16: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

16 renderRadarChart

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

)

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

}

renderRadarChart Render the Radar Chart Plotted by ECharts into Shiny Application

Description

renderRadarChart() function helps render the Radar chart into Shiny application.

Usage

renderRadarChart(div_id, data, theme = "default",shape = "default", line.width = 2,show.legend = TRUE, show.tools = TRUE,font.size.legend = 12,animation = TRUE,running_in_shiny = TRUE)

Arguments

div_id The division id users specified for this chart. The division will be specified inui.R.

data The data used for the plotting. It should be a data.frame. For radar chart, thedata must have row names and column names specified.

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

shape The shape of the radar chart. Valid values include "default" and "circle".

line.width The width of the lines in the radar chart.

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.

animation Whether display the chart with animation. 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 supposedto evaluate.

Page 17: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

renderScatter 17

Note

Users need to state the division for the chart first, with tags$div() function of Shiny packages. Pleasenote 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

if (interactive()) {library(shiny)library(ECharts2Shiny)

dat <- data.frame(Type.A = c(4300, 10000, 25000, 35000, 50000),Type.B = c(5000, 14000, 28000, 31000, 42000),Type.C = c(4000, 2000, 9000, 29000, 35000))

row.names(dat) <- c("Feture 1", "Feature 2", "Feature 3", "Feature 4", "Feature 5")

# Server function -------------------------------------------server <- function(input, output) {renderRadarChart(div_id = "test",

data = dat)}

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

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

)

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

}

renderScatter Render the Scatter Plots Plotted by ECharts into Shiny Application

Description

renderScatter() function helps render the scatter plots into Shiny applications.

Page 18: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

18 renderScatter

Usage

renderScatter(div_id, data,point.size = 10, point.type = "circle",theme = "default", auto.scale = TRUE,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,show.slider.axis.x = FALSE, show.slider.axis.y = FALSE,animation = TRUE,

grid_left = "3%", grid_right = "4%", grid_top = "16%", grid_bottom = "3%",running_in_shiny = TRUE)

Arguments

div_id The division id users specified for this chart. The division will be specified inui.R.

data The data used for the plotting. It should be a data.frame. For scatter plots, thedata must be made up of three columns, "x", "y", and "group".

point.size This argument helps set the size of points in the scatter plots. It should be asingle numeric or integer value. The dafault value is 10.

point.type The shape of the points in scatter plots.Valid values include ’emptyCircle’, ’circle’, ’rect’, ’roundRect’, ’triangle’, ’dia-mond’, ’pin’, ’arrow’. The default value is ’circle’.The length of this argument should either be one or be the same as the numberof UNIQUE groups (the number of unique elements in ’group’ column of thedata input).

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

auto.scale A logical argument to determine if the scatter plot should be scaled again auto-matically after the users exclude any group of observations. The default value isTRUE.

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.

Page 19: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

renderScatter 19

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.show.slider.axis.x

Whether display slider on X axis. The default value is FALSE.show.slider.axis.y

Whether display slider on Y axis. The default value is FALSE.

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

grid_left Distance between grid component and the left side of the container. Defaultvalue is "3%".

grid_right Distance between grid component and the right side of the container. Defaultvalue is "4%".

grid_top Distance between grid component and the top side of the container. Defaultvalue is "16%".

grid_bottom Distance between grid component and the bottom side of the container. Defaultvalue is "3%".

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 supposedto evaluate.

Note

Users need to state the division for the chart first, with tags$div() function of Shiny packages. Pleasenote 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

if (interactive()) {library(shiny)library(ECharts2Shiny)

dat <- data.frame(x = iris$Sepal.Length,y = iris$Sepal.Width,group = iris$Species)

# Server function -------------------------------------------server <- function(input, output) {renderScatter("test", data = dat)

}

# UI layout -------------------------------------------------

Page 20: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

20 renderTreeMap

ui <- fluidPage(# We MUST load the ECharts javascript library in advanceloadEChartsLibrary(),

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

)

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

}

renderTreeMap Render Interactive Tree Map into Shiny Application

Description

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

Usage

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 inui.R.

data The data used for tree map. Not like other charts, here we need to use JSON datafor the tree map charts, since there may be nested data which can be handled byJSON 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 beconverted to its ceiling value automatically). The default value is 2.

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

Page 21: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

renderTreeMap 21

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 supposedto evaluate.

Note

Users need to state the division for the chart first, with tags$div() function of Shiny packages. Pleasenote 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

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: [

Page 22: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

22 renderWordcloud

{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 chartsrenderTreeMap(div_id = "test",

data = dat)}

# UI layout -------------------------------------------------ui <- fluidPage(

# We MUST load the ECharts javascript library in advanceloadEChartsLibrary(),

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

)

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

}

renderWordcloud Render the Word Cloud Plotted by ECharts into Shiny Application

Description

renderWordcloud() function helps render the word cloud charts into Shiny applications.

Usage

renderWordcloud(div_id, data,shape = 'circle',grid_size = 5, sizeRange = c(15, 50),rotationRange = c(-45, 45),hyperlinks = NULL,running_in_shiny = TRUE)

Page 23: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

renderWordcloud 23

Arguments

div_id The division id users specified for this chart. The division will be specified inui.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 andplot, 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.

shape The shape of the word cloud. The valid values include "circle" (default value),"cardioid", "diamond", "triangle-forward", "triangle", "pentagon" and "star".

grid_size The size of the grid in word cloud.

sizeRange The font size range in the word cloud. It should be a vector of length two. Thedefault value is c(15, 50).

rotationRange The rotation angle range in the word cloud. It should be a vector of length two.The default value is c(-45, 45).

hyperlinks Vector. Users can link each element in the chart to a hyperlink (URL likehttp://***.com). Please note this is only supported when the data is in data.frameformat, and the length of the "hyperlinks" vector should be the same to the num-ber of rows in the data given.Note that if hyperlinks are available, the fonts in the pop-up window will be inskyblue 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 supposedto evaluate.

Note

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

Author(s)

Xiaodong DENG

(ECharts library is authored by Baidu team)

References

https://github.com/ecomfe/echarts-wordcloud

Examples

if (interactive()) {library(shiny)library(ECharts2Shiny)

Page 24: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

24 renderWordcloud

sample_data_for_wordcloud <- c(rep("R", 100),rep("Python", 100),rep("SAS", 90),rep("VBA", 50))

# Server function -------------------------------------------server <- function(input, output) {

renderWordcloud("test", data =sample_data_for_wordcloud,grid_size = 10, sizeRange = c(20, 50))

}

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

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

)

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

}

Page 25: Package ‘ECharts2Shiny’ · Package ‘ECharts2Shiny ... These charts will be gener-ated by ECharts library developed by Baidu (

Index

deliverChart, 2

loadEChartsLibrary, 3loadEChartsTheme, 4

renderBarChart, 5renderGauge, 8renderHeatMap, 9renderLineChart, 11renderPieChart, 14renderRadarChart, 16renderScatter, 17renderTreeMap, 20renderWordcloud, 22

25