├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── charts.R ├── data.R ├── echart.R ├── options.R ├── package.R ├── shiny.R └── utils.R ├── README.md ├── inst └── htmlwidgets │ ├── echarts.js │ ├── echarts.yaml │ └── lib │ └── echarts │ └── echarts-all.js ├── man ├── axis.Rd ├── eChart.Rd ├── recharts-imports.Rd └── recharts-shiny.Rd ├── recharts.Rproj └── vignettes └── intro.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | sudo: false 4 | 5 | env: 6 | matrix: 7 | - R_PKG="$(basename $TRAVIS_REPO_SLUG)" 8 | global: 9 | secure: UTJJhiel0TE8NgLhE9lLtXcZiqWT7y2UObDZ8aAU1ZFiL9S4u/MTDU9Ea3pOGgzSWE1aUU7lquVjtf1funLpEwHyRXWHCfee+1e37AE7EN+gC7QclHoL6S7L2lIf0srMOiDkANyei342qoF7iYDXjDac1bfBlvk0z5kN3Qmcz/8= 10 | 11 | addons: 12 | apt: 13 | sources: 14 | - r-packages-precise 15 | packages: 16 | - r-base-dev 17 | - r-recommended 18 | 19 | install: 20 | - "wget -q -O - http://yihui.name/xran/r-config | bash" 21 | - "[ ! -d ~/bin ] && mkdir ~/bin || true" 22 | - "export PATH=$HOME/bin:$PATH" 23 | - "wget -q -O - https://github.com/yihui/crandalf/raw/master/inst/scripts/install-pandoc | bash" 24 | - Rscript -e "if (!require('devtools')) install.packages('devtools')" 25 | - Rscript -e "devtools::install_deps(dep = TRUE)" 26 | 27 | cache: 28 | directories: 29 | - $HOME/R 30 | - $HOME/bin 31 | 32 | script: 33 | - cd ..; rm -f *.tar.gz; R CMD build $R_PKG 34 | - R CMD check ${R_PKG}_*.tar.gz --no-manual 35 | - cd $R_PKG 36 | 37 | # deploy to XRAN 38 | after_success: 39 | - set -e 40 | - "(wget -q -O - http://yihui.name/xran/r-xran | bash)" 41 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: recharts 2 | Type: Package 3 | Title: An R Interface to ECharts 4 | Version: 0.0.3 5 | Date: 2014-12-18 6 | Authors@R: c( 7 | person("Liyun", "Chen", role = "aut"), 8 | person("Taiyun", "Wei", role = c("aut", "cre"), email = "weitaiyun@gmail.com"), 9 | person("Yihui", "Xie", role = "aut"), 10 | person("Yang", "Zhou", role = "aut"), 11 | person("Baidu Inc", role = c("ctb", "cph"), comment = "the ECharts library under htmlwidgets/lib") 12 | ) 13 | Description: Provides an R interface to the JavaScript library ECharts for 14 | interactive data visualization. 15 | Imports: 16 | htmltools, 17 | htmlwidgets (>= 0.4), 18 | magrittr 19 | Suggests: 20 | knitr, 21 | rmarkdown, 22 | shiny (>= 0.12.1) 23 | License: MIT + file LICENSE 24 | LazyData: TRUE 25 | VignetteBuilder: knitr 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2014-2015 2 | COPYRIGHT HOLDER: Taiyun Wei, Yihui Xie, Yang Zhou 3 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | S3method(echart,data.frame) 2 | S3method(echart,default) 3 | S3method(echart,list) 4 | export("%>%") 5 | export(JS) 6 | export(eAxis) 7 | export(eChart) 8 | export(eChartOutput) 9 | export(eXAxis) 10 | export(eYAxis) 11 | export(echart) 12 | export(renderEChart) 13 | importFrom(htmlwidgets,JS) 14 | importFrom(magrittr,"%>%") 15 | -------------------------------------------------------------------------------- /R/charts.R: -------------------------------------------------------------------------------- 1 | eLine = function(chart, ...) { 2 | 3 | } 4 | 5 | eBar = function(chart, ...) { 6 | 7 | } 8 | 9 | eScatter = function(chart, ...) { 10 | 11 | } 12 | 13 | eK = function(chart, ...) { 14 | 15 | } 16 | 17 | ePie = function(chart, ...) { 18 | 19 | } 20 | 21 | eRadar = function(chart, ...) { 22 | 23 | } 24 | 25 | eChord = function(chart, ...) { 26 | 27 | } 28 | 29 | eForce = function(chart, ...) { 30 | 31 | } 32 | 33 | eMap = function(chart, ...) { 34 | 35 | } 36 | 37 | eGauge = function(chart, ...) { 38 | 39 | } 40 | 41 | eFunnel = function(chart, ...) { 42 | 43 | } 44 | 45 | eEventRiver = function(chart, ...) { 46 | 47 | } 48 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | # split the data matrix for a scatterplot by series 2 | data_scatter = function(x, y, series = NULL, type = 'scatter') { 3 | xy = unname(cbind(x, y)) 4 | if (is.null(series)) return(list(list(type = type, data = xy))) 5 | xy = split(as.data.frame(xy), series) 6 | nms = names(xy) 7 | obj = list() 8 | for (i in seq_along(xy)) { 9 | obj[[i]] = list(name = nms[i], type = type, data = unname(as.matrix(xy[[i]]))) 10 | } 11 | obj 12 | } 13 | 14 | data_bar = function(x, y, series = NULL, type = 'bar') { 15 | 16 | # plot the frequencies of x when y is not provided 17 | if (is.null(y)) { 18 | 19 | if (is.null(series)) { 20 | y = table(x) 21 | return(list(list(type = type, data = unname(c(y))))) 22 | } 23 | 24 | y = table(x, series) 25 | nms = colnames(y) 26 | obj = list() 27 | for (i in seq_len(ncol(y))) { 28 | obj[[i]] = list(name = nms[i], type = type, data = unname(y[, i])) 29 | } 30 | return(obj) 31 | 32 | } 33 | 34 | # when y is provided, use y as the height of bars 35 | if (is.null(series)) { 36 | return(list(list(type = type, data = y))) 37 | } 38 | 39 | xy = tapply(y, list(x, series), function(z) { 40 | if (length(z) == 1) return(z) 41 | stop('y must only have one value corresponding to each combination of x and series') 42 | }) 43 | nms = colnames(xy) 44 | obj = list() 45 | for (i in seq_len(ncol(xy))) { 46 | obj[[i]] = list(name = nms[i], type = type, data = unname(xy[, i])) 47 | } 48 | obj 49 | 50 | } 51 | 52 | data_line = function(x, y, series = NULL) { 53 | if (is.null(x) && is.ts(y)) { 54 | x = as.numeric(time(y)) 55 | y = as.numeric(y) 56 | } 57 | if (is.numeric(x)) { 58 | return(data_scatter(x, y, series, type = 'line')) 59 | } 60 | if (is.null(series)) { 61 | return(list(list(type = 'line', data = y))) 62 | } 63 | data_bar(x, y, series, type = 'line') 64 | } 65 | -------------------------------------------------------------------------------- /R/echart.R: -------------------------------------------------------------------------------- 1 | #' Create an ECharts widget 2 | #' 3 | #' Create an HTML widget for ECharts that can be rendered in the R console, R 4 | #' Markdown documents, or Shiny apps. You can add more components to this widget 5 | #' and customize options later. \code{eChart()} is an alias of \code{echart()}. 6 | #' @param data a data object (usually a data frame or a list) 7 | #' @rdname eChart 8 | #' @export 9 | #' @examples library(recharts) 10 | #' echart(iris, ~ Sepal.Length, ~ Sepal.Width) 11 | #' echart(iris, ~ Sepal.Length, ~ Sepal.Width, series = ~ Species) 12 | echart = function(data, ...) { 13 | UseMethod('echart') 14 | } 15 | 16 | #' @export 17 | #' @rdname eChart 18 | echart.list = function(data, width = NULL, height = NULL, ...) { 19 | htmlwidgets::createWidget( 20 | 'echarts', data, width = width, height = height, package = 'recharts' 21 | ) 22 | } 23 | 24 | #' @param x the x variable 25 | #' @param y the y variable 26 | #' @export 27 | #' @rdname eChart 28 | echart.data.frame = function( 29 | data = NULL, x = NULL, y = NULL, series = NULL, type = 'auto', 30 | width = NULL, height = NULL, ... 31 | ) { 32 | 33 | xlab = autoArgLabel(x, deparse(substitute(x))) 34 | ylab = autoArgLabel(y, deparse(substitute(y))) 35 | 36 | x = evalFormula(x, data) 37 | y = evalFormula(y, data) 38 | if (type == 'auto') type = determineType(x, y) 39 | if (type == 'bar') { 40 | x = as.factor(x) 41 | if (is.null(y)) ylab = 'Frequency' 42 | } 43 | 44 | series = evalFormula(series, data) 45 | data_fun = getFromNamespace(paste0('data_', type), 'recharts') 46 | 47 | params = structure(list( 48 | series = data_fun(x, y, series), 49 | xAxis = list(), yAxis = list() 50 | ), meta = list( 51 | x = x, y = y 52 | )) 53 | 54 | if (!is.null(series)) { 55 | params$legend = list(data = levels(as.factor(series))) 56 | } 57 | 58 | chart = htmlwidgets::createWidget( 59 | 'echarts', params, width = width, height = height, package = 'recharts', 60 | dependencies = getDependency(NULL) 61 | ) 62 | 63 | chart %>% eAxis('x', name = xlab) %>% eAxis('y', name = ylab) 64 | } 65 | 66 | #' @export 67 | #' @rdname eChart 68 | echart.default = echart.data.frame 69 | 70 | #' @export 71 | #' @rdname eChart 72 | eChart = echart 73 | # from the planet of "Duo1 Qiao1 Yi1 Ge4 Jian4 Hui4 Si3" (will die if having to 74 | # press one more key, i.e. Shift in this case) 75 | 76 | determineType = function(x, y) { 77 | if (is.numeric(x) && is.numeric(y)) return('scatter') 78 | # when y is numeric, plot y against x; when y is NULL, treat x as a 79 | # categorical variable, and plot its frequencies 80 | if ((is.factor(x) || is.character(x)) && (is.numeric(y) || is.null(y))) 81 | return('bar') 82 | if (is.null(x) && is.ts(y)) return('line') 83 | # FIXME: 'histogram' is not a standard plot type of ECharts 84 | # http://echarts.baidu.com/doc/doc.html 85 | if (is.numeric(x) && is.null(y)) return('histogram') 86 | message('The structure of x:') 87 | str(x) 88 | message('The structure of y:') 89 | str(y) 90 | stop('Unable to determine the chart type from x and y automatically') 91 | } 92 | 93 | # not usable yet; see https://github.com/ecomfe/echarts/issues/1065 94 | getDependency = function(type) { 95 | if (is.null(type)) return() 96 | htmltools::htmlDependency( 97 | 'echarts-module', EChartsVersion, 98 | src = system.file('htmlwidgets/lib/echarts/chart', package = 'recharts'), 99 | script = sprintf('%s.js', type) 100 | ) 101 | } 102 | 103 | getMeta = function(chart) { 104 | attr(chart$x, 'meta', exact = TRUE) 105 | } 106 | -------------------------------------------------------------------------------- /R/options.R: -------------------------------------------------------------------------------- 1 | #' Create an axis for a chart 2 | #' 3 | #' Add an axis to a chart. 4 | #' 5 | #' This function modified a few default options for the axis component in 6 | #' ECharts: 1) \code{scale = TRUE} (was \code{FALSE} by default in ECharts); 2) 7 | #' \code{axisLine$onZero = FALSE} (was \code{TRUE} in ECharts). 8 | #' @export 9 | #' @rdname axis 10 | eAxis = function( 11 | chart, which = c('x', 'y'), 12 | type = c('value', 'category', 'time'), show = TRUE, 13 | position = c('bottom', 'top', 'left', 'right'), 14 | name = '', nameLocation = c('end', 'start'), nameTextStyle = emptyList(), 15 | boundaryGap = c(0, 0), min = NULL, max = NULL, scale = TRUE, splitNumber = NULL, 16 | axisLine = list(show = TRUE, onZero = FALSE), axisTick = list(show = FALSE), 17 | axisLabel = list(show = TRUE), splitLine = list(show = TRUE), 18 | splitArea = list(show = FALSE), data = list() 19 | ) { 20 | which = match.arg(which) 21 | odata = getMeta(chart)[[which]] # original data along the axis 22 | if (missing(type)) type = axisType(odata, which) 23 | if (missing(position)) position = if (which == 'x') 'bottom' else 'left' 24 | if (missing(data) && type == 'category') { 25 | data = I(levels(as.factor(odata))) 26 | } 27 | 28 | x = chart$x 29 | i = paste0(which, 'Axis') 30 | o = list( 31 | type = match.arg(type), show = show, position = match.arg(position), 32 | name = name, nameLocation = match.arg(nameLocation), nameTextStyle = nameTextStyle, 33 | boundaryGap = boundaryGap, min = min, max = max, scale = scale, 34 | splitNumber = splitNumber, axisLine = axisLine, axisTick = axisTick, 35 | axisLabel = axisLabel, splitLine = splitLine, splitArea = splitArea, data = data 36 | ) 37 | if (length(x[[i]])) { 38 | # only merge the arguments that are not missing, e.g. eAxis(min = 0) will 39 | # only override 'min' but will not override the 'name' attribute 40 | a = intersect(names(as.list(match.call()[-1])), names(o))#;browser() 41 | x[[i]] = mergeList(x[[i]], o[a]) 42 | } else { 43 | x[[i]] = mergeList(x[[i]], o) 44 | } 45 | chart$x = x 46 | 47 | chart 48 | } 49 | 50 | #' @export 51 | #' @rdname axis 52 | eXAxis = function(chart, ...) { 53 | eAxis(chart, which = 'x', ...) 54 | } 55 | 56 | #' @export 57 | #' @rdname axis 58 | eYAxis = function(chart, ...) { 59 | eAxis(chart, which = 'y', ...) 60 | } 61 | 62 | axisType = function(data, which = c('x', 'y')) { 63 | if (is.numeric(data) || is.null(data)) return('value') 64 | if (is.factor(data) || is.character(data)) return('category') 65 | if (inherits(data, 'Date')) return('time') 66 | message('The structure of the ', which, ' variable:') 67 | str(data) 68 | stop('Unable to derive the axis type automatically from the ', which, ' variable') 69 | } 70 | -------------------------------------------------------------------------------- /R/package.R: -------------------------------------------------------------------------------- 1 | #' @importFrom magrittr %>% 2 | #' @export %>% 3 | #' @importFrom htmlwidgets JS 4 | #' @export JS 5 | NULL 6 | 7 | EChartsVersion = '2.2.3' 8 | -------------------------------------------------------------------------------- /R/shiny.R: -------------------------------------------------------------------------------- 1 | #' Wrapper functions for Shiny 2 | #' 3 | #' Use \code{eChartOutput()} to create a container for a ECharts widget in the 4 | #' UI, and \code{renderEChart()} to render the widget on the server side. 5 | #' @param outputId the output id to be used in the \code{output} object on the 6 | #' server side 7 | #' @param width the width of the chart 8 | #' @param height the height of the chart 9 | #' @rdname recharts-shiny 10 | #' @export 11 | #' @examples # !formatR 12 | #' \donttest{library(recharts) 13 | #' library(shiny) 14 | #' app = shinyApp( 15 | #' ui = fluidPage(eChartOutput('myChart')), 16 | #' server = function(input, output) { 17 | #' chart = echart(x = rnorm(100), y = rnorm(100)) 18 | #' output$myChart = renderEChart(chart) 19 | #' } 20 | #' ) 21 | #' 22 | #' if (interactive()) print(app)} 23 | eChartOutput = function(outputId, width = '100%', height = '400px') { 24 | htmlwidgets::shinyWidgetOutput(outputId, 'echarts', width, height, package = 'recharts') 25 | } 26 | 27 | #' @param expr an R expression to return an EChart widget 28 | #' @inheritParams htmlwidgets::shinyRenderWidget 29 | #' @rdname recharts-shiny 30 | #' @export 31 | renderEChart = function(expr, env = parent.frame(), quoted = FALSE) { 32 | if (!quoted) expr = substitute(expr) # force quoted 33 | htmlwidgets::shinyRenderWidget(expr, eChartOutput, env, quoted = TRUE) 34 | } 35 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | # make sure htmlwidgets:::toJSON() turns list() to {} in JSON, instead of [] 2 | .emptyList = setNames(list(), character()) 3 | emptyList = function() .emptyList 4 | 5 | # evaluate a formula using `data` as the environment, e.g. evalFormula(~ z + 1, 6 | # data = data.frame(z = 1:10)) 7 | evalFormula = function(x, data) { 8 | if (!inherits(x, 'formula')) return(x) 9 | if (length(x) != 2) stop('The formula must be one-sided: ', deparse(x)) 10 | eval(x[[2]], data, environment(x)) 11 | } 12 | 13 | # merge two lists by names, e.g. x = list(a = 1, b = 2), mergeList(x, list(b = 14 | # 3)) => list(a = 1, b = 3) 15 | mergeList = function(x, y) { 16 | if (!is.list(y) || length(y) == 0) return(x) 17 | yn = names(y) 18 | if (length(yn) == 0 || any(yn == '')) { 19 | warning('The second list to be merged into the first must be named') 20 | return(x) 21 | } 22 | for (i in yn) { 23 | xi = x[[i]] 24 | yi = y[[i]] 25 | if (is.list(xi)) { 26 | if (is.list(yi)) x[[i]] = mergeList(xi, yi) 27 | } else x[[i]] = yi 28 | } 29 | x 30 | } 31 | 32 | # automatic labels from function arguments 33 | autoArgLabel = function(arg, auto) { 34 | if (is.null(arg)) return('') 35 | if (inherits(arg, 'formula')) return(deparse(arg[[2]])) 36 | auto 37 | } 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # recharts 2 | 3 | [![Build Status](https://travis-ci.org/yihui/recharts.svg)](https://travis-ci.org/yihui/recharts) 4 | 5 | This is a prototype of porting [Apache ECharts (incubating)](https://echarts.apache.org/) into R using **htmlwidgets**. I only spent a few days on it last year, and I hope more R users can contribute to it. To install this package (please use [R >= 3.2.0](http://cran.rstudio.com/)): 6 | 7 | ```r 8 | install.packages( 9 | 'recharts', 10 | repos = c('http://yihui.name/xran', 'http://cran.rstudio.com') 11 | ) 12 | ``` 13 | 14 | Some "hello world" examples: 15 | 16 | ```r 17 | library(recharts) 18 | echart(iris, ~Sepal.Length, ~Sepal.Width) 19 | echart(iris, ~Sepal.Length, ~Sepal.Width, series = ~Species) 20 | ``` 21 | 22 | See https://github.com/taiyun/recharts for a similar project that we worked on before. Without the blessings of **htmlwidgets**, it is much more difficult to maintain that project. I hope this one can grow into a truly nice and exciting package. 23 | See the package website for more information if you want to contribute. 24 | -------------------------------------------------------------------------------- /inst/htmlwidgets/echarts.js: -------------------------------------------------------------------------------- 1 | HTMLWidgets.widget({ 2 | name: 'echarts', 3 | type: 'output', 4 | 5 | initialize: function(el, width, height) { 6 | return echarts.init(el); 7 | }, 8 | 9 | renderValue: function(el, x, instance) { 10 | instance.setOption(x); 11 | }, 12 | 13 | resize: function(el, width, height, instance) { 14 | } 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /inst/htmlwidgets/echarts.yaml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | - name: echarts 3 | version: 2.2.3 4 | src: htmlwidgets/lib/echarts 5 | script: echarts-all.js 6 | -------------------------------------------------------------------------------- /man/axis.Rd: -------------------------------------------------------------------------------- 1 | % Please edit documentation in R/options.R 2 | \name{eAxis} 3 | \alias{eAxis} 4 | \alias{eXAxis} 5 | \alias{eYAxis} 6 | \title{Create an axis for a chart} 7 | \usage{ 8 | eAxis(chart, which = c("x", "y"), type = c("value", "category", "time"), show = TRUE, 9 | position = c("bottom", "top", "left", "right"), name = "", nameLocation = c("end", 10 | "start"), nameTextStyle = emptyList(), boundaryGap = c(0, 0), min = NULL, 11 | max = NULL, scale = TRUE, splitNumber = NULL, axisLine = list(show = TRUE, 12 | onZero = FALSE), axisTick = list(show = FALSE), axisLabel = list(show = TRUE), 13 | splitLine = list(show = TRUE), splitArea = list(show = FALSE), data = list()) 14 | 15 | eXAxis(chart, ...) 16 | 17 | eYAxis(chart, ...) 18 | } 19 | \description{ 20 | Add an axis to a chart. 21 | } 22 | \details{ 23 | This function modified a few default options for the axis component in 24 | ECharts: 1) \code{scale = TRUE} (was \code{FALSE} by default in ECharts); 2) 25 | \code{axisLine$onZero = FALSE} (was \code{TRUE} in ECharts). 26 | } 27 | -------------------------------------------------------------------------------- /man/eChart.Rd: -------------------------------------------------------------------------------- 1 | % Please edit documentation in R/echart.R 2 | \name{echart} 3 | \alias{eChart} 4 | \alias{echart} 5 | \alias{echart.data.frame} 6 | \alias{echart.default} 7 | \alias{echart.list} 8 | \title{Create an ECharts widget} 9 | \usage{ 10 | echart(data, ...) 11 | 12 | \method{echart}{list}(data, width = NULL, height = NULL, ...) 13 | 14 | \method{echart}{data.frame}(data = NULL, x = NULL, y = NULL, series = NULL, 15 | type = "auto", width = NULL, height = NULL, ...) 16 | 17 | \method{echart}{default}(data = NULL, x = NULL, y = NULL, series = NULL, type = "auto", 18 | width = NULL, height = NULL, ...) 19 | 20 | eChart(data, ...) 21 | } 22 | \arguments{ 23 | \item{data}{a data object (usually a data frame or a list)} 24 | 25 | \item{x}{the x variable} 26 | 27 | \item{y}{the y variable} 28 | } 29 | \description{ 30 | Create an HTML widget for ECharts that can be rendered in the R console, R 31 | Markdown documents, or Shiny apps. You can add more components to this widget 32 | and customize options later. \code{eChart()} is an alias of \code{echart()}. 33 | } 34 | \examples{ 35 | library(recharts) 36 | echart(iris, ~Sepal.Length, ~Sepal.Width) 37 | echart(iris, ~Sepal.Length, ~Sepal.Width, series = ~Species) 38 | } 39 | -------------------------------------------------------------------------------- /man/recharts-imports.Rd: -------------------------------------------------------------------------------- 1 | \name{recharts-imports} 2 | \alias{JS} 3 | \alias{\%>\%} 4 | \docType{import} 5 | \title{Objects imported from other packages} 6 | \description{ 7 | These objects are imported from other packages. Follow the links to their documentation. 8 | \describe{ 9 | \item{htmlwidgets}{\code{\link[htmlwidgets:JS]{JS}}} 10 | \item{magrittr}{\code{\link[magrittr:\%>\%]{\%>\%}}} 11 | }} 12 | -------------------------------------------------------------------------------- /man/recharts-shiny.Rd: -------------------------------------------------------------------------------- 1 | % Please edit documentation in R/shiny.R 2 | \name{eChartOutput} 3 | \alias{eChartOutput} 4 | \alias{renderEChart} 5 | \title{Wrapper functions for Shiny} 6 | \usage{ 7 | eChartOutput(outputId, width = "100\%", height = "400px") 8 | 9 | renderEChart(expr, env = parent.frame(), quoted = FALSE) 10 | } 11 | \arguments{ 12 | \item{outputId}{the output id to be used in the \code{output} object on the 13 | server side} 14 | 15 | \item{width}{the width of the chart} 16 | 17 | \item{height}{the height of the chart} 18 | 19 | \item{expr}{an R expression to return an EChart widget} 20 | 21 | \item{env}{The environment in which to evaluate \code{expr}.} 22 | 23 | \item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This 24 | is useful if you want to save an expression in a variable.} 25 | } 26 | \description{ 27 | Use \code{eChartOutput()} to create a container for a ECharts widget in the 28 | UI, and \code{renderEChart()} to render the widget on the server side. 29 | } 30 | \examples{ 31 | \donttest{library(recharts) 32 | library(shiny) 33 | app = shinyApp( 34 | ui = fluidPage(eChartOutput('myChart')), 35 | server = function(input, output) { 36 | chart = echart(x = rnorm(100), y = rnorm(100)) 37 | output$myChart = renderEChart(chart) 38 | } 39 | ) 40 | 41 | if (interactive()) print(app)} 42 | } 43 | -------------------------------------------------------------------------------- /recharts.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: XeLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageInstallArgs: --with-keep.source 20 | PackageBuildArgs: -v && Rscript -e "Rd2roxygen::rab(install=TRUE)" 21 | PackageCheckArgs: --as-cran 22 | -------------------------------------------------------------------------------- /vignettes/intro.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "An Introduction to the recharts Package" 3 | author: "Yihui Xie" 4 | date: "`r Sys.Date()`" 5 | output: knitr:::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{An Introduction to the recharts Package} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | Please see the package website http://yihui.name/recharts for the full documentation. Here are some quick examples: 13 | 14 | ```{r} 15 | library(recharts) 16 | # you can also write: iris %>% echart(~Sepal.Length, ~Sepal.Width) 17 | echart(iris, ~Sepal.Length, ~Sepal.Width) 18 | echart(iris, ~Sepal.Length, ~Sepal.Width, series = ~Species) 19 | ``` 20 | --------------------------------------------------------------------------------