2018-08-02 16:47:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ApexCharts options ------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-03 11:10:36 +02:00
|
|
|
#' Events options
|
|
|
|
#'
|
2019-02-17 22:07:04 +01:00
|
|
|
#' @param click Fires when user clicks on any area of the chart.
|
|
|
|
#' @param beforeMount Fires before the chart has been drawn on screen.
|
|
|
|
#' @param mounted Fires after the chart has been drawn on screen.
|
|
|
|
#' @param updated Fires when the chart has been dynamically updated.
|
|
|
|
#' @param legendClick Fires when user clicks on legend.
|
|
|
|
#' @param selection Fires when user selects rect using the selection tool.
|
|
|
|
#' @param dataPointSelection Fires when user clicks on a datapoint (bar/column/marker/bubble/donut-slice).
|
2020-02-14 18:13:24 +01:00
|
|
|
#' @param dataPointMouseEnter Fires when user's mouse enter on a datapoint (bar/column/marker/bubble/donut-slice).
|
2019-02-17 22:07:04 +01:00
|
|
|
#' @param dataPointMouseLeave MouseLeave event for a datapoint (bar/column/marker/bubble/donut-slice).
|
|
|
|
#' @param beforeZoom This function, if defined, runs just before zooming in/out of the chart allowing you to set a custom range for zooming in/out.
|
|
|
|
#' @param zoomed Fires when user zooms in/out the chart using either the selection zooming tool or zoom in/out buttons.
|
|
|
|
#' @param scrolled Fires when user scrolls using the pan tool.
|
2018-08-03 11:10:36 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
2019-02-17 22:07:04 +01:00
|
|
|
#' @note All arguments should be JavaScript function defined with \code{htmlwidgets::JS}.
|
2019-07-24 12:20:22 +02:00
|
|
|
#'
|
|
|
|
#' @return A \code{list} of options that can be used in \code{\link{ax_chart}}.
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
2019-02-17 22:07:04 +01:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/chart/events/}.
|
|
|
|
#'
|
2018-08-03 11:10:36 +02:00
|
|
|
#' @export
|
2019-07-24 12:20:22 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#'
|
|
|
|
#' if (interactive()) {
|
|
|
|
#' library(shiny)
|
|
|
|
#'
|
|
|
|
#' ui <- fluidPage(
|
|
|
|
#' fluidRow(
|
|
|
|
#' column(
|
|
|
|
#' width = 8, offset = 2,
|
|
|
|
#' tags$h2("Apexchart in Shiny"),
|
|
|
|
#' apexchartOutput("chart"),
|
|
|
|
#' verbatimTextOutput(outputId = "res_click")
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#'
|
|
|
|
#' server <- function(input, output, session) {
|
|
|
|
#'
|
|
|
|
#' output$chart <- renderApexchart({
|
|
|
|
#' apexchart() %>%
|
|
|
|
#' ax_chart(
|
|
|
|
#' type = "bar",
|
|
|
|
#' events = events_opts(
|
|
|
|
#' dataPointSelection = JS(
|
|
|
|
#' "function(event, chartContext, config) {
|
|
|
|
#' Shiny.setInputValue('click', config.selectedDataPoints)
|
|
|
|
#' }"
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_series(
|
|
|
|
#' list(
|
|
|
|
#' name = "Example",
|
|
|
|
#' data = sample(1:100, 5)
|
|
|
|
#' )
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_xaxis(
|
|
|
|
#' categories = LETTERS[1:5]
|
|
|
|
#' )
|
|
|
|
#' })
|
|
|
|
#'
|
|
|
|
#' output$res_click <- renderPrint({
|
|
|
|
#' input$click
|
|
|
|
#' })
|
|
|
|
#' }
|
|
|
|
#'
|
|
|
|
#' shinyApp(ui, server)
|
|
|
|
#' }
|
2019-02-17 22:07:04 +01:00
|
|
|
events_opts <- function(click = NULL,
|
|
|
|
beforeMount = NULL,
|
|
|
|
mounted = NULL,
|
|
|
|
updated = NULL,
|
|
|
|
legendClick = NULL,
|
|
|
|
selection = NULL,
|
|
|
|
dataPointSelection = NULL,
|
|
|
|
dataPointMouseEnter = NULL,
|
|
|
|
dataPointMouseLeave = NULL,
|
|
|
|
beforeZoom = NULL,
|
|
|
|
zoomed = NULL,
|
|
|
|
scrolled = NULL,
|
|
|
|
...) {
|
2018-08-02 16:47:32 +02:00
|
|
|
dropNulls(
|
|
|
|
list(
|
2019-02-17 22:07:04 +01:00
|
|
|
click = click,
|
2018-08-02 16:47:32 +02:00
|
|
|
beforeMount = beforeMount,
|
|
|
|
mounted = mounted,
|
|
|
|
updated = updated,
|
2019-02-17 22:07:04 +01:00
|
|
|
legendClick = legendClick,
|
2018-08-02 16:47:32 +02:00
|
|
|
selection = selection,
|
|
|
|
dataPointSelection = dataPointSelection,
|
2019-02-17 22:07:04 +01:00
|
|
|
dataPointMouseEnter = dataPointMouseEnter,
|
|
|
|
dataPointMouseLeave = dataPointMouseLeave,
|
|
|
|
beforeZoom = beforeZoom,
|
2018-08-02 16:47:32 +02:00
|
|
|
zoomed = zoomed,
|
|
|
|
scrolled = scrolled,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-24 12:20:22 +02:00
|
|
|
#' @title Bar options
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
2019-07-24 12:20:22 +02:00
|
|
|
#' @description Use these options in \code{\link{ax_plotOptions}}.
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
2019-07-15 11:28:48 +02:00
|
|
|
#' @param horizontal Logical. This option will turn a column chart into a horizontal bar chart.
|
2019-06-24 15:18:38 +02:00
|
|
|
#' @param endingShape Available Options: \code{"flat"} or \code{"rounded"}.
|
2018-08-03 11:10:36 +02:00
|
|
|
#' @param columnWidth In column charts, columnWidth is the percentage of the available width in the grid-rect.
|
|
|
|
#' @param barHeight In horizontal bar charts, barHeight is the percentage of the available height in the grid-rect.
|
|
|
|
#' @param distributed Logical. Turn this option to make the bars discrete. Each value indicates one bar per series.
|
2019-02-17 22:07:04 +01:00
|
|
|
#' @param colors A list of parameters.
|
2018-08-03 11:10:36 +02:00
|
|
|
#' @param dataLabels List with fields \code{position} (available options: \code{"top"}, \code{"center"} or \code{"bottom"})
|
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/bar/}.
|
2019-07-24 12:20:22 +02:00
|
|
|
#'
|
|
|
|
#' @return A \code{list} of options that can be used in \code{\link{ax_plotOptions}}.
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
|
|
|
#' @export
|
2019-07-19 14:11:41 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#'
|
|
|
|
#' data("mpg", package = "ggplot2")
|
|
|
|
#'
|
2021-01-15 10:53:51 +01:00
|
|
|
#' apex(mpg, aes(manufacturer)) %>%
|
2019-07-19 14:11:41 +02:00
|
|
|
#' ax_plotOptions(
|
|
|
|
#' bar = bar_opts(
|
|
|
|
#' endingShape = "rounded",
|
|
|
|
#' columnWidth = 100,
|
|
|
|
#' distributed = TRUE
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#'
|
2019-02-17 22:07:04 +01:00
|
|
|
bar_opts <- function(horizontal = NULL,
|
|
|
|
endingShape = NULL,
|
|
|
|
columnWidth = NULL,
|
|
|
|
barHeight = NULL,
|
|
|
|
distributed = NULL,
|
|
|
|
colors = NULL,
|
|
|
|
dataLabels = NULL,
|
|
|
|
...) {
|
2018-08-02 16:47:32 +02:00
|
|
|
dropNulls(
|
|
|
|
list(
|
|
|
|
horizontal = horizontal,
|
|
|
|
endingShape = endingShape,
|
|
|
|
columnWidth = columnWidth,
|
|
|
|
barHeight = barHeight,
|
|
|
|
distributed = distributed,
|
|
|
|
colors = colors,
|
|
|
|
dataLabels = dataLabels,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-24 12:20:22 +02:00
|
|
|
#' @title Heatmap options
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
2019-07-24 12:20:22 +02:00
|
|
|
#' @description Use these options in \code{\link{ax_plotOptions}}.
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
|
|
|
#' @param radius Numeric. Radius of the rectangle inside heatmap.
|
|
|
|
#' @param enableShades Logical. Enable different shades of color depending on the value
|
|
|
|
#' @param shadeIntensity Numeric \code{[0,1]}. The intensity of the shades generated for each value.
|
|
|
|
#' @param colorScale List.
|
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/heatmap/}.
|
2019-07-24 12:20:22 +02:00
|
|
|
#'
|
|
|
|
#' @return A \code{list} of options that can be used in \code{\link{ax_plotOptions}}.
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
|
|
|
#' @export
|
2019-07-19 14:11:41 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#'
|
|
|
|
#' df <- expand.grid(
|
|
|
|
#' month = month.name,
|
|
|
|
#' person = c("Obi-Wan", "Luke", "Anakin", "Leia")
|
|
|
|
#' )
|
|
|
|
#' df$value <- sample(0:1, nrow(df), TRUE)
|
|
|
|
#'
|
|
|
|
#' apex(
|
|
|
|
#' data = df,
|
|
|
|
#' mapping = aes(x = month, y = person, fill = value),
|
|
|
|
#' type = "heatmap"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_plotOptions(
|
|
|
|
#' heatmap = heatmap_opts(
|
|
|
|
#' enableShades = FALSE,
|
|
|
|
#' colorScale = list(
|
|
|
|
#' ranges = list(
|
|
|
|
#' list(from = 0, to = 0.5, color = "#FF0000"),
|
|
|
|
#' list(from = 0.5, to = 1, color = "#088A08")
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#'
|
2019-02-17 22:07:04 +01:00
|
|
|
heatmap_opts <- function(radius = NULL,
|
|
|
|
enableShades = NULL,
|
|
|
|
shadeIntensity = NULL,
|
|
|
|
colorScale = NULL,
|
|
|
|
...) {
|
2018-08-02 16:47:32 +02:00
|
|
|
dropNulls(
|
|
|
|
list(
|
|
|
|
radius = radius,
|
|
|
|
enableShades = enableShades,
|
|
|
|
shadeIntensity = shadeIntensity,
|
|
|
|
colorScale = colorScale,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-24 12:20:22 +02:00
|
|
|
#' @title Radial bar options
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
2019-07-24 12:20:22 +02:00
|
|
|
#' @description Use these options in \code{\link{ax_plotOptions}}.
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
|
|
|
#' @param size Numeric. Manual size of the radialBars instead of calculating automatically from default height / width.
|
|
|
|
#' @param inverseOrder Logical. Whether to make the first value of series innermost or outermost.
|
|
|
|
#' @param startAngle Numeric. Angle from which the radialBars should start.
|
|
|
|
#' @param endAngle Numeric. Angle to which the radialBars should end. The sum of the startAngle and endAngle should not exceed 360.
|
|
|
|
#' @param offsetX Numeric. Sets the left offset for radialBars.
|
|
|
|
#' @param offsetY Numeric. Sets the top offset for radialBars.
|
|
|
|
#' @param hollow List.
|
|
|
|
#' @param track List.
|
|
|
|
#' @param dataLabels List.
|
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/radialbar/}.
|
2019-07-24 12:20:22 +02:00
|
|
|
#'
|
|
|
|
#' @return A \code{list} of options that can be used in \code{\link{ax_plotOptions}}.
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
|
|
|
#' @export
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' apexchart() %>%
|
|
|
|
#' ax_chart(type = "radialBar") %>%
|
|
|
|
#' ax_plotOptions(
|
|
|
|
#' radialBar = radialBar_opts(
|
|
|
|
#' 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")
|
2019-02-17 22:07:04 +01:00
|
|
|
radialBar_opts <- function(size = NULL,
|
|
|
|
inverseOrder = NULL,
|
|
|
|
startAngle = NULL,
|
|
|
|
endAngle = NULL,
|
|
|
|
offsetX = NULL,
|
|
|
|
offsetY = NULL,
|
|
|
|
hollow = NULL,
|
|
|
|
track = NULL,
|
|
|
|
dataLabels = NULL,
|
|
|
|
...) {
|
2018-08-02 16:47:32 +02:00
|
|
|
dropNulls(
|
|
|
|
list(
|
|
|
|
size = size,
|
|
|
|
inverseOrder = inverseOrder,
|
|
|
|
startAngle = startAngle,
|
|
|
|
endAngle = endAngle,
|
|
|
|
offsetX = offsetX,
|
|
|
|
offsetY = offsetY,
|
|
|
|
hollow = hollow,
|
|
|
|
track = track,
|
|
|
|
dataLabels = dataLabels,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-24 12:20:22 +02:00
|
|
|
#' @title Pie options
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
2019-07-24 12:20:22 +02:00
|
|
|
#' @description Use these options in \code{\link{ax_plotOptions}}.
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
|
|
|
#' @param size Numeric. Custom size of the pie which will override the default size calculations.
|
2019-07-19 14:11:41 +02:00
|
|
|
#' @param donut List with two fields \code{size} (Donut / ring size in percentage relative to the total pie area.)
|
2018-08-03 11:10:36 +02:00
|
|
|
#' and \code{background} (The background color of the pie).
|
|
|
|
#' @param customScale Numeric. Transform the scale of whole pie/donut overriding the default calculations.
|
|
|
|
#' @param offsetX Numeric. Sets the left offset of the whole pie area.
|
|
|
|
#' @param offsetY Numeric. Sets the top offset of the whole pie area.
|
|
|
|
#' @param dataLabels List with field \code{offset} (Numeric, Offset by which labels will move outside / inside of the donut area)
|
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/pie/}.
|
2019-07-24 12:20:22 +02:00
|
|
|
#'
|
|
|
|
#' @return A \code{list} of options that can be used in \code{\link{ax_plotOptions}}.
|
2018-08-03 11:10:36 +02:00
|
|
|
#'
|
|
|
|
#' @export
|
2019-07-19 14:11:41 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' data("mpg", package = "ggplot2")
|
|
|
|
#'
|
2021-01-15 10:53:51 +01:00
|
|
|
#' apex(mpg, aes(cyl), type = "donut") %>%
|
2019-07-19 14:11:41 +02:00
|
|
|
#' ax_plotOptions(
|
|
|
|
#' pie = pie_opts(
|
|
|
|
#' donut = list(size = "90%", background = "#BABABA")
|
|
|
|
#' )
|
|
|
|
#' )
|
2019-02-17 22:07:04 +01:00
|
|
|
pie_opts <- function(size = NULL,
|
|
|
|
donut = NULL,
|
|
|
|
customScale = NULL,
|
|
|
|
offsetX = NULL,
|
|
|
|
offsetY = NULL,
|
|
|
|
dataLabels = NULL,
|
|
|
|
...) {
|
2018-08-02 16:47:32 +02:00
|
|
|
dropNulls(
|
|
|
|
list(
|
|
|
|
size = size,
|
|
|
|
donut = donut,
|
|
|
|
customScale = customScale,
|
|
|
|
offsetX = offsetX,
|
|
|
|
offsetY = offsetY,
|
|
|
|
dataLabels = dataLabels,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-04-17 16:46:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
#' @title Bubble options
|
|
|
|
#'
|
|
|
|
#' @description Use these options in \code{\link{ax_plotOptions}}.
|
|
|
|
#'
|
|
|
|
#' @param minBubbleRadius Minimum radius size of a bubble.
|
|
|
|
#' If a bubble value is too small to be displayed, this size will be used.
|
|
|
|
#' @param maxBubbleRadius Maximum radius size of a bubble.
|
|
|
|
#' If a bubble value is too large to cover the chart, this size will be used.
|
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/bubble/}.
|
|
|
|
#'
|
|
|
|
#' @return A \code{list} of options that can be used in \code{\link{ax_plotOptions}}.
|
|
|
|
#' @export
|
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' apex(
|
|
|
|
#' data = mtcars,
|
|
|
|
#' type = "scatter",
|
|
|
|
#' mapping = aes(x = wt, y = mpg, z = qsec)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_plotOptions(
|
|
|
|
#' bubble = bubble_opts(
|
|
|
|
#' minBubbleRadius = 1,
|
|
|
|
#' maxBubbleRadius = 20
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
bubble_opts <- function(minBubbleRadius, maxBubbleRadius, ...) {
|
|
|
|
dropNulls(
|
|
|
|
list(
|
|
|
|
minBubbleRadius = minBubbleRadius,
|
|
|
|
maxBubbleRadius = maxBubbleRadius,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|