move examples
This commit is contained in:
parent
cfd5a9e712
commit
00fe467dcc
|
@ -8,3 +8,4 @@
|
||||||
^docs$
|
^docs$
|
||||||
^cran-comments\.md$
|
^cran-comments\.md$
|
||||||
^CRAN-RELEASE$
|
^CRAN-RELEASE$
|
||||||
|
^examples$
|
||||||
|
|
38
R/apex.R
38
R/apex.R
|
@ -20,43 +20,7 @@
|
||||||
#' @importFrom rlang eval_tidy as_label
|
#' @importFrom rlang eval_tidy as_label
|
||||||
#' @importFrom utils modifyList
|
#' @importFrom utils modifyList
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @example examples/apex.R
|
||||||
#' library(dplyr)
|
|
||||||
#'
|
|
||||||
#'
|
|
||||||
#' # make a barchart with a frequency table
|
|
||||||
#' data("mpg", package = "ggplot2")
|
|
||||||
#' apex(
|
|
||||||
#' data = count(mpg, manufacturer),
|
|
||||||
#' mapping = aes(x = manufacturer, y = n),
|
|
||||||
#' type = "bar"
|
|
||||||
#' )
|
|
||||||
#'
|
|
||||||
#' # timeseries
|
|
||||||
#' data("economics", package = "ggplot2")
|
|
||||||
#' apex(
|
|
||||||
#' data = economics,
|
|
||||||
#' mapping = aes(x = date, y = uempmed),
|
|
||||||
#' type = "line"
|
|
||||||
#' )
|
|
||||||
#'
|
|
||||||
#' # you can add option to apex result :
|
|
||||||
#' apex(
|
|
||||||
#' data = economics,
|
|
||||||
#' mapping = aes(x = date, y = uempmed),
|
|
||||||
#' type = "line"
|
|
||||||
#' ) %>%
|
|
||||||
#' ax_stroke(width = 1)
|
|
||||||
#'
|
|
||||||
#'
|
|
||||||
#'
|
|
||||||
#' # with group variable
|
|
||||||
#' data("economics_long", package = "ggplot2")
|
|
||||||
#' apex(
|
|
||||||
#' data = economics_long,
|
|
||||||
#' mapping = aes(x = date, y = value01, group = variable),
|
|
||||||
#' type = "line"
|
|
||||||
#' )
|
|
||||||
apex <- function(data, mapping, type = "column", ..., auto_update = TRUE, width = NULL, height = NULL, elementId = NULL) {
|
apex <- function(data, mapping, type = "column", ..., auto_update = TRUE, width = NULL, height = NULL, elementId = NULL) {
|
||||||
type <- match.arg(type, c("column", "bar", "line", "area", "spline", "area-spline",
|
type <- match.arg(type, c("column", "bar", "line", "area", "spline", "area-spline",
|
||||||
"pie", "donut", "radialBar", "radar", "scatter", "heatmap"))
|
"pie", "donut", "radialBar", "radar", "scatter", "heatmap"))
|
||||||
|
|
|
@ -12,42 +12,7 @@
|
||||||
#'
|
#'
|
||||||
#' @importFrom htmlwidgets createWidget sizingPolicy
|
#' @importFrom htmlwidgets createWidget sizingPolicy
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @example examples/apexchart.R
|
||||||
#'
|
|
||||||
#' library(apexcharter)
|
|
||||||
#'
|
|
||||||
#' # Use raw API by passing a list of
|
|
||||||
#' # parameters to the function
|
|
||||||
#'
|
|
||||||
#' apexchart(ax_opts = list(
|
|
||||||
#' chart = list(
|
|
||||||
#' type = "bar"
|
|
||||||
#' ),
|
|
||||||
#' series = list(list(
|
|
||||||
#' name = "Example",
|
|
||||||
#' data = sample(1:100, 5)
|
|
||||||
#' )),
|
|
||||||
#' xaxis = list(
|
|
||||||
#' categories = LETTERS[1:5]
|
|
||||||
#' )
|
|
||||||
#' ))
|
|
||||||
#'
|
|
||||||
#'
|
|
||||||
#' # Or use apexchart() to initialize the chart
|
|
||||||
#' # before passing parameters
|
|
||||||
#'
|
|
||||||
#' apexchart() %>%
|
|
||||||
#' ax_chart(type = "bar") %>%
|
|
||||||
#' ax_series(
|
|
||||||
#' list(
|
|
||||||
#' name = "Example",
|
|
||||||
#' data = sample(1:100, 5)
|
|
||||||
#' )
|
|
||||||
#' ) %>%
|
|
||||||
#' ax_xaxis(
|
|
||||||
#' categories = LETTERS[1:5]
|
|
||||||
#' )
|
|
||||||
#'
|
|
||||||
apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height = NULL, elementId = NULL) {
|
apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height = NULL, elementId = NULL) {
|
||||||
|
|
||||||
# forward options using x
|
# forward options using x
|
||||||
|
@ -102,43 +67,7 @@ apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height
|
||||||
#'
|
#'
|
||||||
#' @importFrom htmlwidgets shinyWidgetOutput shinyRenderWidget
|
#' @importFrom htmlwidgets shinyWidgetOutput shinyRenderWidget
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @example examples/apexcharter-shiny.R
|
||||||
#'
|
|
||||||
#' if (interactive()) {
|
|
||||||
#' library(shiny)
|
|
||||||
#'
|
|
||||||
#' ui <- fluidPage(
|
|
||||||
#' fluidRow(
|
|
||||||
#' column(
|
|
||||||
#' width = 8, offset = 2,
|
|
||||||
#' tags$h2("Apexchart in Shiny"),
|
|
||||||
#' actionButton("redraw", "Redraw chart"),
|
|
||||||
#' apexchartOutput("chart")
|
|
||||||
#' )
|
|
||||||
#' )
|
|
||||||
#' )
|
|
||||||
#'
|
|
||||||
#' server <- function(input, output, session) {
|
|
||||||
#'
|
|
||||||
#' output$chart <- renderApexchart({
|
|
||||||
#' input$redraw
|
|
||||||
#' apexchart() %>%
|
|
||||||
#' ax_chart(type = "bar") %>%
|
|
||||||
#' ax_series(
|
|
||||||
#' list(
|
|
||||||
#' name = "Example",
|
|
||||||
#' data = sample(1:100, 5)
|
|
||||||
#' )
|
|
||||||
#' ) %>%
|
|
||||||
#' ax_xaxis(
|
|
||||||
#' categories = LETTERS[1:5]
|
|
||||||
#' )
|
|
||||||
#' })
|
|
||||||
#'
|
|
||||||
#' }
|
|
||||||
#'
|
|
||||||
#' shinyApp(ui, server)
|
|
||||||
#' }
|
|
||||||
apexchartOutput <- function(outputId, width = '100%', height = '400px'){
|
apexchartOutput <- function(outputId, width = '100%', height = '400px'){
|
||||||
htmlwidgets::shinyWidgetOutput(outputId, 'apexcharter', width, height, package = 'apexcharter')
|
htmlwidgets::shinyWidgetOutput(outputId, 'apexcharter', width, height, package = 'apexcharter')
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
library(ggplot2)
|
||||||
|
library(dplyr)
|
||||||
|
library(apexcharter)
|
||||||
|
|
||||||
|
# make a barchart with a frequency table
|
||||||
|
data("mpg", package = "ggplot2")
|
||||||
|
apex(
|
||||||
|
data = count(mpg, manufacturer),
|
||||||
|
mapping = aes(x = manufacturer, y = n),
|
||||||
|
type = "bar"
|
||||||
|
)
|
||||||
|
|
||||||
|
# timeseries
|
||||||
|
data("economics", package = "ggplot2")
|
||||||
|
apex(
|
||||||
|
data = economics,
|
||||||
|
mapping = aes(x = date, y = uempmed),
|
||||||
|
type = "line"
|
||||||
|
)
|
||||||
|
|
||||||
|
# you can add option to apex result :
|
||||||
|
apex(
|
||||||
|
data = economics,
|
||||||
|
mapping = aes(x = date, y = uempmed),
|
||||||
|
type = "line"
|
||||||
|
) %>%
|
||||||
|
ax_stroke(width = 1)
|
||||||
|
|
||||||
|
|
||||||
|
# with group variable
|
||||||
|
data("economics_long", package = "ggplot2")
|
||||||
|
apex(
|
||||||
|
data = economics_long,
|
||||||
|
mapping = aes(x = date, y = value01, group = variable),
|
||||||
|
type = "line"
|
||||||
|
)
|
|
@ -0,0 +1,33 @@
|
||||||
|
library(apexcharter)
|
||||||
|
|
||||||
|
# Use raw API by passing a list of
|
||||||
|
# parameters to the function
|
||||||
|
|
||||||
|
apexchart(ax_opts = list(
|
||||||
|
chart = list(
|
||||||
|
type = "bar"
|
||||||
|
),
|
||||||
|
series = list(list(
|
||||||
|
name = "Example",
|
||||||
|
data = sample(1:100, 5)
|
||||||
|
)),
|
||||||
|
xaxis = list(
|
||||||
|
categories = LETTERS[1:5]
|
||||||
|
)
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
# Or use apexchart() to initialize the chart
|
||||||
|
# before passing parameters
|
||||||
|
|
||||||
|
apexchart() %>%
|
||||||
|
ax_chart(type = "bar") %>%
|
||||||
|
ax_series(
|
||||||
|
list(
|
||||||
|
name = "Example",
|
||||||
|
data = sample(1:100, 5)
|
||||||
|
)
|
||||||
|
) %>%
|
||||||
|
ax_xaxis(
|
||||||
|
categories = LETTERS[1:5]
|
||||||
|
)
|
|
@ -0,0 +1,36 @@
|
||||||
|
if (interactive()) {
|
||||||
|
library(shiny)
|
||||||
|
library(apexcharter)
|
||||||
|
|
||||||
|
ui <- fluidPage(
|
||||||
|
fluidRow(
|
||||||
|
column(
|
||||||
|
width = 8, offset = 2,
|
||||||
|
tags$h2("Apexchart in Shiny"),
|
||||||
|
actionButton("redraw", "Redraw chart"),
|
||||||
|
apexchartOutput("chart")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
server <- function(input, output, session) {
|
||||||
|
|
||||||
|
output$chart <- renderApexchart({
|
||||||
|
input$redraw
|
||||||
|
apexchart() %>%
|
||||||
|
ax_chart(type = "bar") %>%
|
||||||
|
ax_series(
|
||||||
|
list(
|
||||||
|
name = "Example",
|
||||||
|
data = sample(1:100, 5)
|
||||||
|
)
|
||||||
|
) %>%
|
||||||
|
ax_xaxis(
|
||||||
|
categories = LETTERS[1:5]
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
shinyApp(ui, server)
|
||||||
|
}
|
|
@ -40,8 +40,9 @@ A \code{apexcharts} \code{htmlwidget} object.
|
||||||
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{
|
\examples{
|
||||||
|
library(ggplot2)
|
||||||
library(dplyr)
|
library(dplyr)
|
||||||
|
library(apexcharter)
|
||||||
|
|
||||||
# make a barchart with a frequency table
|
# make a barchart with a frequency table
|
||||||
data("mpg", package = "ggplot2")
|
data("mpg", package = "ggplot2")
|
||||||
|
@ -68,7 +69,6 @@ apex(
|
||||||
ax_stroke(width = 1)
|
ax_stroke(width = 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# with group variable
|
# with group variable
|
||||||
data("economics_long", package = "ggplot2")
|
data("economics_long", package = "ggplot2")
|
||||||
apex(
|
apex(
|
||||||
|
|
|
@ -30,7 +30,6 @@ A \code{apexcharts} \code{htmlwidget} object.
|
||||||
Create a apexcharts.js widget
|
Create a apexcharts.js widget
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
|
|
||||||
library(apexcharter)
|
library(apexcharter)
|
||||||
|
|
||||||
# Use raw API by passing a list of
|
# Use raw API by passing a list of
|
||||||
|
@ -64,5 +63,4 @@ apexchart() \%>\%
|
||||||
ax_xaxis(
|
ax_xaxis(
|
||||||
categories = LETTERS[1:5]
|
categories = LETTERS[1:5]
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ Output and render functions for using apexcharter within Shiny
|
||||||
applications and interactive Rmd documents.
|
applications and interactive Rmd documents.
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
|
|
||||||
if (interactive()) {
|
if (interactive()) {
|
||||||
library(shiny)
|
library(shiny)
|
||||||
|
library(apexcharter)
|
||||||
|
|
||||||
ui <- fluidPage(
|
ui <- fluidPage(
|
||||||
fluidRow(
|
fluidRow(
|
||||||
|
|
Loading…
Reference in New Issue