2020-03-03 20:05:03 +01:00
|
|
|
|
2020-03-04 11:55:23 +01:00
|
|
|
#' @title Retrieve click information in Shiny
|
|
|
|
#'
|
|
|
|
#' @description According to type of chart, different values are retrieved:
|
|
|
|
#' * **bar and column:** retrieve category (x-axis).
|
|
|
|
#' * **pie and donut:** retrieve label.
|
|
|
|
#' * **time-series:** retrieve x-axis value, you have to display markers
|
|
|
|
#' with size > 0 and set tooltip's options `intersect = TRUE` and `shared = FALSE`.
|
2020-03-04 19:02:01 +01:00
|
|
|
#' * **scatter:** retrieve coordinates.
|
2020-03-03 20:05:03 +01:00
|
|
|
#'
|
|
|
|
#' @param ax An \code{apexcharts} \code{htmlwidget} object.
|
2020-03-04 19:02:01 +01:00
|
|
|
#' @param inputId The id that will be used server-side for retrieving click.
|
2020-03-04 10:25:20 +01:00
|
|
|
#' @param multiple Allow multiple selection: \code{TRUE} or \code{FALSE} (default).
|
2020-03-04 12:04:47 +01:00
|
|
|
#' @param effect_type Type of effect for selected element, default is to use lightly darken color.
|
|
|
|
#' @param effect_value A larger value intensifies the select effect, accept value between 0 and 1.
|
2020-03-04 15:14:02 +01:00
|
|
|
#' @param session The Shiny session.
|
|
|
|
#'
|
2020-03-03 20:05:03 +01:00
|
|
|
#'
|
|
|
|
#' @return An \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
2020-03-04 15:14:02 +01:00
|
|
|
#'
|
|
|
|
#' @importFrom shiny getDefaultReactiveDomain
|
2020-03-03 20:05:03 +01:00
|
|
|
#'
|
|
|
|
#' @examples
|
2020-03-04 12:04:47 +01:00
|
|
|
set_input_click <- function(ax, inputId, multiple = FALSE,
|
|
|
|
effect_type = c("darken", "lighten", "none"),
|
2020-03-04 15:14:02 +01:00
|
|
|
effect_value = 0.35,
|
|
|
|
session = shiny::getDefaultReactiveDomain()) {
|
2020-03-04 12:04:47 +01:00
|
|
|
effect_type <- match.arg(effect_type)
|
|
|
|
ax <- ax_states(ax, active = list(
|
|
|
|
allowMultipleDataPointsSelection = isTRUE(multiple),
|
|
|
|
filter = list(
|
|
|
|
type = effect_type,
|
|
|
|
value = effect_value
|
|
|
|
)
|
|
|
|
))
|
2020-03-04 22:52:13 +01:00
|
|
|
ax$x$shinyEvents$click <- list(
|
2020-03-04 15:14:02 +01:00
|
|
|
inputId = session$ns(inputId)
|
2020-03-03 20:05:03 +01:00
|
|
|
)
|
|
|
|
ax
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-04 19:02:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#' Retrieve zoom information in Shiny
|
|
|
|
#'
|
|
|
|
#' @param ax An \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @param inputId The id that will be used server-side for retrieving click.
|
|
|
|
#' @param session The Shiny session.
|
|
|
|
#'
|
|
|
|
#' @return An \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
set_input_zoom <- function(ax, inputId,
|
|
|
|
session = shiny::getDefaultReactiveDomain()) {
|
2020-03-14 20:41:41 +01:00
|
|
|
ax$x$shinyEvents$zoomed <- list(
|
2020-03-04 19:02:01 +01:00
|
|
|
inputId = session$ns(inputId)
|
|
|
|
)
|
|
|
|
ax
|
|
|
|
}
|
|
|
|
|
|
|
|
|