rename & examples
This commit is contained in:
parent
e5a19e8252
commit
42e736a241
|
@ -1,5 +1,5 @@
|
|||
Package: apexcharter
|
||||
Version: 0.0.0.9100
|
||||
Version: 0.0.0.9110
|
||||
Title: Create Interactive Chart with the JavaScript 'ApexCharts' Library
|
||||
Description: Provides an 'htmlwidgets' interface to 'apexcharts.js'.
|
||||
Authors@R: c(
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# Generated by roxygen2: do not edit by hand
|
||||
|
||||
export("%>%")
|
||||
export(apexcharter)
|
||||
export(apexcharterOutput)
|
||||
export(apexchart)
|
||||
export(apexchartOutput)
|
||||
export(ax_annotations)
|
||||
export(ax_chart)
|
||||
export(ax_colors)
|
||||
|
@ -30,7 +30,7 @@ export(heatmapOpts)
|
|||
export(parse_df)
|
||||
export(pieOpts)
|
||||
export(radialBarOpts)
|
||||
export(renderApexcharter)
|
||||
export(renderApexchart)
|
||||
importFrom(data.table,transpose)
|
||||
importFrom(htmlwidgets,createWidget)
|
||||
importFrom(htmlwidgets,shinyRenderWidget)
|
||||
|
|
|
@ -377,14 +377,14 @@ ax_responsive <- function(ax, ...) {
|
|||
#' @examples
|
||||
#'
|
||||
#' # One serie
|
||||
#' apexcharter() %>%
|
||||
#' apexchart() %>%
|
||||
#' ax_series(list(
|
||||
#' name = "rnorm",
|
||||
#' data = rnorm(10)
|
||||
#' ))
|
||||
#'
|
||||
#' # Two series
|
||||
#' apexcharter() %>%
|
||||
#' apexchart() %>%
|
||||
#' ax_series(
|
||||
#' list(
|
||||
#' name = "rnorm 1",
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#'
|
||||
#' library(apexcharter)
|
||||
#'
|
||||
#' apexcharter(ax_opts = list(
|
||||
#' apexchart(ax_opts = list(
|
||||
#' chart = list(type = "bar"),
|
||||
#' series = list(list(
|
||||
#' name = "Example",
|
||||
|
@ -24,7 +24,7 @@
|
|||
#' )),
|
||||
#' xaxis = list(categories = LETTERS[1:5])
|
||||
#' ))
|
||||
apexcharter <- function(ax_opts = list(), data = NULL, width = NULL, height = NULL, elementId = NULL) {
|
||||
apexchart <- function(ax_opts = list(), data = NULL, width = NULL, height = NULL, elementId = NULL) {
|
||||
|
||||
# forward options using x
|
||||
x <- list(
|
||||
|
@ -73,13 +73,13 @@ apexcharter <- function(ax_opts = list(), data = NULL, width = NULL, height = NU
|
|||
#' @export
|
||||
#'
|
||||
#' @importFrom htmlwidgets shinyWidgetOutput shinyRenderWidget
|
||||
apexcharterOutput <- function(outputId, width = '100%', height = '400px'){
|
||||
apexchartOutput <- function(outputId, width = '100%', height = '400px'){
|
||||
htmlwidgets::shinyWidgetOutput(outputId, 'apexcharter', width, height, package = 'apexcharter')
|
||||
}
|
||||
|
||||
#' @rdname apexcharter-shiny
|
||||
#' @export
|
||||
renderApexcharter <- function(expr, env = parent.frame(), quoted = FALSE) {
|
||||
renderApexchart <- function(expr, env = parent.frame(), quoted = FALSE) {
|
||||
if (!quoted) { expr <- substitute(expr) } # force quoted
|
||||
htmlwidgets::shinyRenderWidget(expr, apexcharterOutput, env, quoted = TRUE)
|
||||
htmlwidgets::shinyRenderWidget(expr, apexchartOutput, env, quoted = TRUE)
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ library(magrittr)
|
|||
data(mpg)
|
||||
dat <- count(mpg, manufacturer)
|
||||
|
||||
apexcharter() %>%
|
||||
apexchart() %>%
|
||||
ax_chart(type = "bar") %>%
|
||||
ax_plotOptions(bar = barOpts(
|
||||
horizontal = FALSE,
|
||||
|
@ -58,7 +58,7 @@ apexcharter() %>%
|
|||
Pass a list of parameters to the function:
|
||||
|
||||
``` r
|
||||
apexcharter(ax_opts = list(
|
||||
apexchart(ax_opts = list(
|
||||
chart = list(
|
||||
type = "line"
|
||||
),
|
||||
|
|
|
@ -13,7 +13,7 @@ library(dplyr)
|
|||
data(mpg)
|
||||
dat <- count(mpg, manufacturer)
|
||||
|
||||
apexcharter(ax_opts = list(
|
||||
apexchart(ax_opts = list(
|
||||
chart = list(type = "bar"),
|
||||
plotOptions = list(
|
||||
bar = list(
|
||||
|
@ -43,7 +43,7 @@ apexcharter(ax_opts = list(
|
|||
|
||||
# recreating (mostly): https://apexcharts.com/javascript-chart-demos/line-charts/data-labels/
|
||||
|
||||
apexcharter(ax_opts = list(
|
||||
apexchart(ax_opts = list(
|
||||
chart = list(
|
||||
type = "line"
|
||||
),
|
||||
|
|
|
@ -23,7 +23,7 @@ library(dplyr) # for count
|
|||
data(mpg)
|
||||
dat <- count(mpg, manufacturer)
|
||||
|
||||
apexcharter() %>%
|
||||
apexchart() %>%
|
||||
ax_chart(type = "bar") %>%
|
||||
ax_plotOptions(bar = barOpts(
|
||||
horizontal = FALSE,
|
||||
|
@ -55,7 +55,7 @@ apexcharter() %>%
|
|||
data(mpg)
|
||||
dat <- count(mpg, manufacturer)
|
||||
|
||||
apexcharter() %>%
|
||||
apexchart() %>%
|
||||
ax_chart(type = "bar") %>%
|
||||
ax_plotOptions(bar = barOpts(
|
||||
horizontal = TRUE,
|
||||
|
@ -82,6 +82,57 @@ apexcharter() %>%
|
|||
|
||||
|
||||
|
||||
# Stacked bar -------------------------------------------------------------
|
||||
|
||||
stacked <- count(mpg, manufacturer, year)
|
||||
|
||||
apexchart() %>%
|
||||
ax_chart(type = "bar", stacked = TRUE) %>%
|
||||
ax_series(
|
||||
list(
|
||||
name = "1999",
|
||||
data = filter(stacked, year == 1999) %>% pull(n)
|
||||
),
|
||||
list(
|
||||
name = "2008",
|
||||
data = filter(stacked, year == 2008) %>% pull(n)
|
||||
)
|
||||
) %>%
|
||||
ax_xaxis(categories = unique(stacked$manufacturer)) %>%
|
||||
ax_legend(
|
||||
position = "right",
|
||||
verticalAlign = "top",
|
||||
offsetX = 0,
|
||||
offsetY = 50
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
# Grouped bar -------------------------------------------------------------
|
||||
|
||||
stacked <- count(mpg, manufacturer, year)
|
||||
|
||||
apexchart() %>%
|
||||
ax_chart(type = "bar", stacked = FALSE) %>%
|
||||
ax_plotOptions(bar = barOpts(
|
||||
endingShape = "rounded"
|
||||
)) %>%
|
||||
ax_series(
|
||||
list(
|
||||
name = "1999",
|
||||
data = filter(stacked, year == 1999) %>% pull(n)
|
||||
),
|
||||
list(
|
||||
name = "2008",
|
||||
data = filter(stacked, year == 2008) %>% pull(n)
|
||||
)
|
||||
) %>%
|
||||
ax_dataLabels(enabled = FALSE) %>%
|
||||
ax_xaxis(categories = unique(stacked$manufacturer))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ data("vaccines")
|
|||
#O trying to recreate "The Impact of Vaccines" (http://jkunst.com/highcharter/showcase.html)
|
||||
|
||||
|
||||
apexcharter() %>%
|
||||
apexchart() %>%
|
||||
ax_chart(type = "heatmap") %>%
|
||||
ax_dataLabels(enabled = FALSE) %>%
|
||||
ax_series2(lapply(
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
# ------------------------------------------------------------------------
|
||||
#
|
||||
# Title : Pie charts
|
||||
# By : Victor
|
||||
# Date : 2018-09-07
|
||||
#
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
# Packages ----------------------------------------------------------------
|
||||
|
||||
library(apexcharter)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Simple pie --------------------------------------------------------------
|
||||
|
||||
apexchart() %>%
|
||||
ax_chart(type = "pie") %>%
|
||||
ax_series(23, 45, 56)
|
||||
|
||||
|
||||
|
||||
|
||||
# Donut -------------------------------------------------------------------
|
||||
|
||||
|
||||
apexchart() %>%
|
||||
ax_chart(type = "donut") %>%
|
||||
ax_series2(l = c(23, 45, 56))
|
||||
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
|
||||
# ------------------------------------------------------------------------
|
||||
#
|
||||
# Title : Radial charts
|
||||
# By : Victor
|
||||
# Date : 2018-09-07
|
||||
#
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
# Packages ----------------------------------------------------------------
|
||||
|
||||
library(apexcharter)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Basic -------------------------------------------------------------------
|
||||
|
||||
apexchart() %>%
|
||||
ax_chart(type = "radialBar") %>%
|
||||
ax_plotOptions(
|
||||
radialBar = radialBarOpts(
|
||||
hollow = list(size = "70%")
|
||||
)
|
||||
) %>%
|
||||
ax_series(70) %>%
|
||||
ax_labels("Indicator")
|
||||
|
||||
|
||||
|
||||
|
||||
# Stroked gauge -----------------------------------------------------------
|
||||
|
||||
apexchart() %>%
|
||||
ax_chart(type = "radialBar") %>%
|
||||
ax_plotOptions(
|
||||
radialBar = radialBarOpts(
|
||||
startAngle = -135,
|
||||
endAngle = 135,
|
||||
dataLabels = list(
|
||||
name = list(
|
||||
fontSize = "16px",
|
||||
# color = undefined,
|
||||
offsetY = 120
|
||||
),
|
||||
value = list(
|
||||
offsetY = 76,
|
||||
fontSize = "22px",
|
||||
# color = undefined,
|
||||
formatter = htmlwidgets::JS("function (val) {return val + '%';}")
|
||||
)
|
||||
)
|
||||
)
|
||||
) %>%
|
||||
ax_stroke(dashArray = 4) %>%
|
||||
ax_series(70) %>%
|
||||
ax_labels("Indicator")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ data("economics", package = "ggplot2")
|
|||
# One serie (class Date) --------------------------------------------------
|
||||
|
||||
|
||||
apexcharter() %>%
|
||||
apexchart() %>%
|
||||
ax_chart(type = "area", zoom = list(enabled = TRUE)) %>%
|
||||
ax_plotOptions(line = list(curve = "smooth")) %>%
|
||||
ax_dataLabels(enabled = FALSE) %>%
|
||||
|
@ -60,7 +60,7 @@ apexcharter() %>%
|
|||
|
||||
# Two series (Date) -------------------------------------------------------
|
||||
|
||||
apexcharter() %>%
|
||||
apexchart() %>%
|
||||
ax_chart(type = "line", zoom = list(enabled = TRUE)) %>%
|
||||
ax_plotOptions(line = list(curve = "smooth")) %>%
|
||||
ax_dataLabels(enabled = FALSE) %>%
|
||||
|
@ -89,3 +89,30 @@ apexcharter() %>%
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Scroller (zoom) ---------------------------------------------------------
|
||||
|
||||
apexchart() %>%
|
||||
ax_chart(type = "area", scroller = list(enabled = TRUE)) %>%
|
||||
ax_dataLabels(enabled = FALSE) %>%
|
||||
ax_series(list(
|
||||
name = "personal savings rate",
|
||||
data = parse_df(economics[, c("date", "psavert")])
|
||||
)) %>%
|
||||
ax_title(text = "US economic time series", align = "left") %>%
|
||||
ax_subtitle(text = "Data from ggplot2") %>%
|
||||
ax_yaxis(
|
||||
min = 0, max = 20,
|
||||
tickAmount = 4,
|
||||
labels = list(
|
||||
formatter = htmlwidgets::JS("function(val) {return val.toFixed(0);}")
|
||||
),
|
||||
title = "Personal savings rate"
|
||||
) %>%
|
||||
ax_xaxis(type = "datetime", labels = list(format = "d MMM yy"))
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,10 @@ HTMLWidgets.widget({
|
|||
chart.render();
|
||||
|
||||
},
|
||||
|
||||
getChart: function(){
|
||||
return chart;
|
||||
},
|
||||
|
||||
resize: function(width, height) {
|
||||
chart.updateOptions({
|
||||
|
@ -41,3 +45,37 @@ HTMLWidgets.widget({
|
|||
};
|
||||
}
|
||||
});
|
||||
|
||||
// From Friss tuto (https://github.com/FrissAnalytics/shinyJsTutorials/blob/master/tutorials/tutorial_03.Rmd)
|
||||
function get_widget(id){
|
||||
|
||||
// Get the HTMLWidgets object
|
||||
var htmlWidgetsObj = HTMLWidgets.find("#" + id);
|
||||
|
||||
// Use the getChart method we created to get the underlying billboard chart
|
||||
var widgetObj ;
|
||||
|
||||
if (typeof htmlWidgetsObj != 'undefined') {
|
||||
widgetObj = htmlWidgetsObj.getChart();
|
||||
}
|
||||
|
||||
return(widgetObj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (HTMLWidgets.shinyMode) {
|
||||
// data = load
|
||||
Shiny.addCustomMessageHandler('update-apexcharts-series',
|
||||
function(obj) {
|
||||
var chart = get_widget(data.id);
|
||||
if (typeof chart != 'undefined') {
|
||||
chart.updateSeries(obj.newSeries, obj.animate);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/apexcharter.R
|
||||
\name{apexcharter}
|
||||
\alias{apexcharter}
|
||||
\name{apexchart}
|
||||
\alias{apexchart}
|
||||
\title{Create a apexcharts.js widget}
|
||||
\usage{
|
||||
apexcharter(ax_opts = list(), data = NULL, width = NULL,
|
||||
apexchart(ax_opts = list(), data = NULL, width = NULL,
|
||||
height = NULL, elementId = NULL)
|
||||
}
|
||||
\arguments{
|
||||
|
@ -28,7 +28,7 @@ Create a apexcharts.js widget
|
|||
|
||||
library(apexcharter)
|
||||
|
||||
apexcharter(ax_opts = list(
|
||||
apexchart(ax_opts = list(
|
||||
chart = list(type = "bar"),
|
||||
series = list(list(
|
||||
name = "Example",
|
|
@ -2,13 +2,13 @@
|
|||
% Please edit documentation in R/apexcharter.R
|
||||
\name{apexcharter-shiny}
|
||||
\alias{apexcharter-shiny}
|
||||
\alias{apexcharterOutput}
|
||||
\alias{renderApexcharter}
|
||||
\alias{apexchartOutput}
|
||||
\alias{renderApexchart}
|
||||
\title{Shiny bindings for apexcharter}
|
||||
\usage{
|
||||
apexcharterOutput(outputId, width = "100\%", height = "400px")
|
||||
apexchartOutput(outputId, width = "100\%", height = "400px")
|
||||
|
||||
renderApexcharter(expr, env = parent.frame(), quoted = FALSE)
|
||||
renderApexchart(expr, env = parent.frame(), quoted = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{outputId}{output variable to read from}
|
||||
|
|
|
@ -26,14 +26,14 @@ Add data to a chart
|
|||
\examples{
|
||||
|
||||
# One serie
|
||||
apexcharter() \%>\%
|
||||
apexchart() \%>\%
|
||||
ax_series(list(
|
||||
name = "rnorm",
|
||||
data = rnorm(10)
|
||||
))
|
||||
|
||||
# Two series
|
||||
apexcharter() \%>\%
|
||||
apexchart() \%>\%
|
||||
ax_series(
|
||||
list(
|
||||
name = "rnorm 1",
|
||||
|
|
Loading…
Reference in New Issue