added update_options in apexcharter()
This commit is contained in:
parent
2be3c5b4b3
commit
d44e251f31
7
NEWS.md
7
NEWS.md
|
@ -1,3 +1,10 @@
|
|||
apexcharter 0.1.4
|
||||
==================
|
||||
|
||||
* Upgraded ApexCharts.js to 3.15.5
|
||||
* Fixed a bug in grouped bar charts with different levels in groups.
|
||||
|
||||
|
||||
apexcharter 0.1.3
|
||||
==================
|
||||
|
||||
|
|
28
R/apex.R
28
R/apex.R
|
@ -1,14 +1,21 @@
|
|||
|
||||
#' @title Quick ApexChart
|
||||
#'
|
||||
#' @description Initialize a chart with three main parameters : data, mapping and type of chart.
|
||||
#' @description Initialize a chart with three main parameters :
|
||||
#' data, mapping and type of chart.
|
||||
#'
|
||||
#' @param data Default dataset to use for chart. If not already a \code{data.frame}, it will be coerced to with \code{as.data.frame}.
|
||||
#' @param data Default dataset to use for chart. If not already
|
||||
#' a \code{data.frame}, it will be coerced to with \code{as.data.frame}.
|
||||
#' @param mapping Default list of aesthetic mappings to use for chart
|
||||
#' @param type Specify the chart type. Available Options: \code{"column"}, \code{"bar"}, \code{"line"},
|
||||
#' \code{"area"}, \code{"spline"}, \code{"pie"}, \code{"donut"}, \code{"radialBar"}, \code{"radar"}, \code{"scatter"}, \code{"heatmap"}.
|
||||
#' @param type Specify the chart type. Available Options:
|
||||
#' \code{"column"}, \code{"bar"}, \code{"line"},
|
||||
#' \code{"area"}, \code{"spline"}, \code{"pie"}, \code{"donut"},
|
||||
#' \code{"radialBar"}, \code{"radar"}, \code{"scatter"}, \code{"heatmap"}.
|
||||
#' @param ... Other arguments passed on to methods. Not currently used.
|
||||
#' @param auto_update In Shiny application, update existing chart rather than generating new one.
|
||||
#' @param auto_update In Shiny application, update existing chart
|
||||
#' rather than generating new one.
|
||||
#' @param update_options In Shiny application, update or not global options
|
||||
#' for chart. Applicable only if \code{auto_update} is \code{TRUE}.
|
||||
#' @param width A numeric input in pixels.
|
||||
#' @param height A numeric input in pixels.
|
||||
#' @param elementId Use an explicit element ID for the widget.
|
||||
|
@ -21,7 +28,9 @@
|
|||
#' @importFrom utils modifyList
|
||||
#'
|
||||
#' @example examples/apex.R
|
||||
apex <- function(data, mapping, type = "column", ..., auto_update = TRUE, width = NULL, height = NULL, elementId = NULL) {
|
||||
apex <- function(data, mapping, type = "column", ...,
|
||||
auto_update = TRUE, update_options = FALSE,
|
||||
width = NULL, height = NULL, elementId = NULL) {
|
||||
type <- match.arg(type, c("column", "bar", "line", "area", "spline", "area-spline",
|
||||
"pie", "donut", "radialBar", "radar", "scatter", "heatmap",
|
||||
"rangeBar"))
|
||||
|
@ -44,8 +53,11 @@ apex <- function(data, mapping, type = "column", ..., auto_update = TRUE, width
|
|||
}
|
||||
opts <- modifyList(opts, choose_config(type, mapdata))
|
||||
apexchart(
|
||||
ax_opts = opts, width = width, height = height,
|
||||
elementId = elementId, auto_update = auto_update
|
||||
ax_opts = opts,
|
||||
width = width, height = height,
|
||||
elementId = elementId,
|
||||
auto_update = auto_update,
|
||||
update_options = update_options
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
|
||||
#' Create a apexcharts.js widget
|
||||
#' Create an apexcharts.js widget
|
||||
#'
|
||||
#' @param ax_opts A \code{list} in JSON format with chart parameters.
|
||||
#' @param auto_update In Shiny application, update existing chart rather than generating new one.
|
||||
#' @param auto_update In Shiny application, update existing chart
|
||||
#' rather than generating new one.
|
||||
#' @param update_options In Shiny application, update or not global options
|
||||
#' for chart. Applicable only if \code{auto_update} is \code{TRUE}.
|
||||
#' @param width A numeric input in pixels.
|
||||
#' @param height A numeric input in pixels.
|
||||
#' @param elementId Use an explicit element ID for the widget.
|
||||
|
@ -13,21 +16,21 @@
|
|||
#' @importFrom htmlwidgets createWidget sizingPolicy
|
||||
#'
|
||||
#' @example examples/apexchart.R
|
||||
apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height = NULL, elementId = NULL) {
|
||||
apexchart <- function(ax_opts = list(), auto_update = TRUE, update_options = FALSE, width = NULL, height = NULL, elementId = NULL) {
|
||||
|
||||
# forward options using x
|
||||
x <- list(
|
||||
ax_opts = ax_opts,
|
||||
auto_update = auto_update
|
||||
auto_update = isTRUE(auto_update),
|
||||
update_options = isTRUE(update_options)
|
||||
)
|
||||
|
||||
# create widget
|
||||
htmlwidgets::createWidget(
|
||||
name = 'apexcharter',
|
||||
name = "apexcharter",
|
||||
x = x,
|
||||
width = width,
|
||||
height = height,
|
||||
package = 'apexcharter',
|
||||
package = "apexcharter",
|
||||
elementId = elementId,
|
||||
preRenderHook = function(widget) {
|
||||
if (!is.null(widget$x$ax_opts$chart$defaultLocale)) {
|
||||
|
@ -86,8 +89,8 @@ apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height
|
|||
#' @importFrom htmlwidgets shinyWidgetOutput shinyRenderWidget
|
||||
#'
|
||||
#' @example examples/apexcharter-shiny.R
|
||||
apexchartOutput <- function(outputId, width = '100%', height = '400px'){
|
||||
htmlwidgets::shinyWidgetOutput(outputId, 'apexcharter', width, height, package = 'apexcharter')
|
||||
apexchartOutput <- function(outputId, width = "100%", height = "400px"){
|
||||
htmlwidgets::shinyWidgetOutput(outputId, "apexcharter", width, height, package = "apexcharter")
|
||||
}
|
||||
|
||||
#' @rdname apexcharter-shiny
|
||||
|
|
|
@ -29,14 +29,17 @@ HTMLWidgets.widget({
|
|||
|
||||
// Generate or update chart
|
||||
if (apexchart === null) {
|
||||
apexchart = new ApexCharts(document.querySelector("#" + el.id), ax_opts);
|
||||
apexchart = new ApexCharts(el, ax_opts);
|
||||
apexchart.render();
|
||||
} else {
|
||||
if (x.auto_update) {
|
||||
apexchart.updateSeries(ax_opts.series);
|
||||
if (x.update_options) {
|
||||
apexchart.updateOptions(ax_opts, true);
|
||||
}
|
||||
} else {
|
||||
apexchart.destroy();
|
||||
apexchart = new ApexCharts(document.querySelector("#" + el.id), ax_opts);
|
||||
apexchart = new ApexCharts(el, ax_opts);
|
||||
apexchart.render();
|
||||
}
|
||||
}
|
||||
|
|
19
man/apex.Rd
19
man/apex.Rd
|
@ -10,22 +10,30 @@ apex(
|
|||
type = "column",
|
||||
...,
|
||||
auto_update = TRUE,
|
||||
update_options = FALSE,
|
||||
width = NULL,
|
||||
height = NULL,
|
||||
elementId = NULL
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
\item{data}{Default dataset to use for chart. If not already a \code{data.frame}, it will be coerced to with \code{as.data.frame}.}
|
||||
\item{data}{Default dataset to use for chart. If not already
|
||||
a \code{data.frame}, it will be coerced to with \code{as.data.frame}.}
|
||||
|
||||
\item{mapping}{Default list of aesthetic mappings to use for chart}
|
||||
|
||||
\item{type}{Specify the chart type. Available Options: \code{"column"}, \code{"bar"}, \code{"line"},
|
||||
\code{"area"}, \code{"spline"}, \code{"pie"}, \code{"donut"}, \code{"radialBar"}, \code{"radar"}, \code{"scatter"}, \code{"heatmap"}.}
|
||||
\item{type}{Specify the chart type. Available Options:
|
||||
\code{"column"}, \code{"bar"}, \code{"line"},
|
||||
\code{"area"}, \code{"spline"}, \code{"pie"}, \code{"donut"},
|
||||
\code{"radialBar"}, \code{"radar"}, \code{"scatter"}, \code{"heatmap"}.}
|
||||
|
||||
\item{...}{Other arguments passed on to methods. Not currently used.}
|
||||
|
||||
\item{auto_update}{In Shiny application, update existing chart rather than generating new one.}
|
||||
\item{auto_update}{In Shiny application, update existing chart
|
||||
rather than generating new one.}
|
||||
|
||||
\item{update_options}{In Shiny application, update or not global options
|
||||
for chart. Applicable only if \code{auto_update} is \code{TRUE}.}
|
||||
|
||||
\item{width}{A numeric input in pixels.}
|
||||
|
||||
|
@ -37,7 +45,8 @@ apex(
|
|||
A \code{apexcharts} \code{htmlwidget} object.
|
||||
}
|
||||
\description{
|
||||
Initialize a chart with three main parameters : data, mapping and type of chart.
|
||||
Initialize a chart with three main parameters :
|
||||
data, mapping and type of chart.
|
||||
}
|
||||
\examples{
|
||||
library(ggplot2)
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
% Please edit documentation in R/apexcharter.R
|
||||
\name{apexchart}
|
||||
\alias{apexchart}
|
||||
\title{Create a apexcharts.js widget}
|
||||
\title{Create an apexcharts.js widget}
|
||||
\usage{
|
||||
apexchart(
|
||||
ax_opts = list(),
|
||||
auto_update = TRUE,
|
||||
update_options = FALSE,
|
||||
width = NULL,
|
||||
height = NULL,
|
||||
elementId = NULL
|
||||
|
@ -15,7 +16,11 @@ apexchart(
|
|||
\arguments{
|
||||
\item{ax_opts}{A \code{list} in JSON format with chart parameters.}
|
||||
|
||||
\item{auto_update}{In Shiny application, update existing chart rather than generating new one.}
|
||||
\item{auto_update}{In Shiny application, update existing chart
|
||||
rather than generating new one.}
|
||||
|
||||
\item{update_options}{In Shiny application, update or not global options
|
||||
for chart. Applicable only if \code{auto_update} is \code{TRUE}.}
|
||||
|
||||
\item{width}{A numeric input in pixels.}
|
||||
|
||||
|
@ -27,7 +32,7 @@ apexchart(
|
|||
A \code{apexcharts} \code{htmlwidget} object.
|
||||
}
|
||||
\description{
|
||||
Create a apexcharts.js widget
|
||||
Create an apexcharts.js widget
|
||||
}
|
||||
\examples{
|
||||
library(apexcharter)
|
||||
|
|
Loading…
Reference in New Issue