category -> click + time series

This commit is contained in:
pvictor 2020-03-04 11:55:23 +01:00
parent 4823f7a630
commit 02c267db56
13 changed files with 92 additions and 55 deletions

View File

@ -30,6 +30,7 @@ Suggests:
gapminder,
highcharter
RoxygenNote: 7.0.2
Roxygen: list(markdown = TRUE)
URL: https://github.com/dreamRs/apexcharter, https://dreamrs.github.io/apexcharter
BugReports: https://github.com/dreamRs/apexcharter/issues
VignetteBuilder: knitr

View File

@ -42,7 +42,7 @@ export(parse_df)
export(pie_opts)
export(radialBar_opts)
export(renderApexchart)
export(set_input_category)
export(set_input_click)
importFrom(ggplot2,aes)
importFrom(htmlwidgets,JS)
importFrom(htmlwidgets,createWidget)

View File

@ -1,5 +1,11 @@
#' Retrieve category (x-axis) in Shiny
#' @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`.
#'
#' @param ax An \code{apexcharts} \code{htmlwidget} object.
#' @param inputId The id that will be used server-side for retrieveng category.
@ -9,7 +15,7 @@
#' @export
#'
#' @examples
set_input_category <- function(ax, inputId, multiple = FALSE) {
set_input_click <- function(ax, inputId, multiple = FALSE) {
if (isTRUE(multiple)) {
ax <- ax_states(ax, active = list(
allowMultipleDataPointsSelection = TRUE

View File

@ -3,7 +3,7 @@ library(shiny)
library(apexcharter)
ui <- fluidPage(
tags$h2("Retrieve category clicked"),
tags$h2("Retrieve click information"),
fluidRow(
column(
width = 6,
@ -26,7 +26,11 @@ ui <- fluidPage(
verbatimTextOutput("result3")
),
column(
width = 6
width = 6,
tags$b("Time serie: you must display markers and use"),
tags$code("ax_tooltip(intersect = TRUE, shared = FALSE)"),
apexchartOutput("chart4"),
verbatimTextOutput("result4")
)
)
)
@ -39,7 +43,7 @@ server <- function(input, output, session) {
value = sample(1:100, 12)
) %>%
apex(aes(month, value)) %>%
set_input_category("month_click")
set_input_click("month_click")
})
output$result1 <- renderPrint({
input$month_click
@ -51,7 +55,7 @@ server <- function(input, output, session) {
value = sample(1:100, 12)
) %>%
apex(aes(month, value)) %>%
set_input_category("month_click_mult", multiple = TRUE)
set_input_click("month_click_mult", multiple = TRUE)
})
output$result2 <- renderPrint({
input$month_click_mult
@ -63,12 +67,26 @@ server <- function(input, output, session) {
n = c(254, 238)
) %>%
apex(type = "pie", mapping = aes(x = answer, y = n)) %>%
set_input_category("click_pie")
set_input_click("click_pie")
})
output$result3 <- renderPrint({
input$click_pie
})
output$chart4 <- renderApexchart({
data.frame(
date = seq(as.Date("1960-01-01"), length.out = 24, by = "month"),
value = tail(as.vector(AirPassengers), 24)
) %>%
apex(aes(date, value), "line") %>%
ax_markers(size = 5) %>%
ax_tooltip(intersect = TRUE, shared = FALSE) %>%
set_input_click("click_time")
})
output$result4 <- renderPrint({
input$click_time
})
}
shinyApp(ui, server)
shinyApp(ui, server)

View File

@ -46,7 +46,13 @@ HTMLWidgets.widget({
} else {
var data = opts.w.config.series[opts.seriesIndex].data;
selected = opts.selectedDataPoints[0].map(function(index) {
return data[index].x;
var val = data[index];
if (val.hasOwnProperty("x")) {
val = val.x;
} else {
val = val[0];
}
return val;
});
}
Shiny.setInputValue(

View File

@ -25,7 +25,7 @@ a \code{data.frame}, it will be coerced to with \code{as.data.frame}.}
\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"},
\code{"radialBar"}, \code{"radar"}, \code{"scatter"}, \code{"heatmap"},
\code{"timeline"}.}
\item{...}{Other arguments passed on to methods. Not currently used.}
@ -48,7 +48,7 @@ A \code{apexcharts} \code{htmlwidget} object.
}
\description{
Initialize a chart with three main parameters :
data, mapping and type of chart.
data, mapping and type of chart.
}
\examples{
library(ggplot2)

View File

@ -39,7 +39,7 @@ ax_chart(
Available options: \code{"normal"} or \code{"100\%"}.}
\item{defaultLocale}{Locale to use : \code{"ca"}, \code{"de"}, \code{"el"}, \code{"en"}, \code{"es"}, \code{"fi"}, \code{"fr"},
\code{"hi"}, \code{"hr"}, \code{"hy"}, \code{"id"}, \code{"it"}, \code{"ko"}, \code{"nl"}, \code{"pt-br"},
\code{"hi"}, \code{"hr"}, \code{"hy"}, \code{"id"}, \code{"it"}, \code{"ko"}, \code{"nl"}, \code{"pt-br"},
\code{"ru"}, \code{"se"}, \code{"tr"}, \code{"ua"}.}
\item{locales}{Array of custom locales parameters.}

View File

@ -21,13 +21,13 @@ ax_stroke(
\item{show}{Logical. To show or hide path-stroke / line}
\item{curve}{In line / area charts, whether to draw smooth lines or straight lines.
Available Options: \code{"smooth"} (connects the points in a curve fashion. Also known as spline)
Available Options: \code{"smooth"} (connects the points in a curve fashion. Also known as spline)
and \code{"straight"} (connect the points in straight lines.).}
\item{lineCap}{For setting the starting and ending points of stroke. Available Options:
\code{"butt"} (ends the stroke with a 90-degree angle), \code{"square"}
(similar to butt except that it extends the stroke beyond the length of the path)
and \code{"round"} (ends the path-stroke with a radius that smooths out the start and end points)}
(similar to butt except that it extends the stroke beyond the length of the path)
and \code{"round"} (ends the path-stroke with a radius that smooths out the start and end points)}
\item{width}{Sets the width of border for svg path.}

View File

@ -19,8 +19,8 @@ config_update(
\item{options_animate}{Should the chart animate on re-rendering.}
\item{options_redrawPaths}{When the chart is re-rendered,
should it draw from the existing paths or completely redraw
the chart paths from the beginning. By default, the chart
should it draw from the existing paths or completely redraw
the chart paths from the beginning. By default, the chart
is re-rendered from the existing paths}
}
\description{

View File

@ -1,21 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/shiny-input.R
\name{set_input_category}
\alias{set_input_category}
\title{Retrieve category (x-axis) in Shiny}
\usage{
set_input_category(ax, inputId, multiple = FALSE)
}
\arguments{
\item{ax}{An \code{apexcharts} \code{htmlwidget} object.}
\item{inputId}{The id that will be used server-side for retrieveng category.}
\item{multiple}{Allow multiple selection: \code{TRUE} or \code{FALSE} (default).}
}
\value{
An \code{apexcharts} \code{htmlwidget} object.
}
\description{
Retrieve category (x-axis) in Shiny
}

27
man/set_input_click.Rd Normal file
View File

@ -0,0 +1,27 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/shiny-input.R
\name{set_input_click}
\alias{set_input_click}
\title{Retrieve click information in Shiny}
\usage{
set_input_click(ax, inputId, multiple = FALSE)
}
\arguments{
\item{ax}{An \code{apexcharts} \code{htmlwidget} object.}
\item{inputId}{The id that will be used server-side for retrieveng category.}
\item{multiple}{Allow multiple selection: \code{TRUE} or \code{FALSE} (default).}
}
\value{
An \code{apexcharts} \code{htmlwidget} object.
}
\description{
According to type of chart, different values are retrieved:
\itemize{
\item \strong{bar and column:} retrieve category (x-axis).
\item \strong{pie and donut:} retrieve label.
\item \strong{time-series:} retrieve x-axis value, you have to display markers
with size > 0 and set tooltip's options \code{intersect = TRUE} and \code{shared = FALSE}.
}
}

View File

@ -5,15 +5,15 @@
\alias{unhcr_popstats_2017}
\title{UNHCR data for 2017}
\format{A data frame with 11237 observations on the following 6 variables.
\describe{
\item{\code{country_origin}}{Country of origin of population}
\item{\code{country_residence}}{Country / territory of asylum/residence of population}
\item{\code{population_type}}{Populations of concern : Refugees, Asylum-seekers, Internally displaced persons (IDPs), Returned refugees,
Returned IDPs, Stateless persons, Others of concern.}
\item{\code{value}}{Number of people concerned}
\item{\code{continent_residence}}{Continent of origin of population}
\item{\code{continent_origin}}{Continent of residence of population}
}}
\describe{
\item{\code{country_origin}}{Country of origin of population}
\item{\code{country_residence}}{Country / territory of asylum/residence of population}
\item{\code{population_type}}{Populations of concern : Refugees, Asylum-seekers, Internally displaced persons (IDPs), Returned refugees,
Returned IDPs, Stateless persons, Others of concern.}
\item{\code{value}}{Number of people concerned}
\item{\code{continent_residence}}{Continent of origin of population}
\item{\code{continent_origin}}{Continent of residence of population}
}}
\source{
UNHCR (The UN Refugee Agency) (\url{https://www.unhcr.org/})
}

View File

@ -5,13 +5,13 @@
\alias{unhcr_ts}
\title{UNHCR data by continent of origin}
\format{A data frame with 913 observations on the following 4 variables.
\describe{
\item{\code{year}}{Year concerned.}
\item{\code{population_type}}{Populations of concern : Refugees, Asylum-seekers, Internally displaced persons (IDPs), Returned refugees,
Returned IDPs, Stateless persons, Others of concern.}
\item{\code{continent_origin}}{Continent of residence of population.}
\item{\code{n}}{Number of people concerned.}
}}
\describe{
\item{\code{year}}{Year concerned.}
\item{\code{population_type}}{Populations of concern : Refugees, Asylum-seekers, Internally displaced persons (IDPs), Returned refugees,
Returned IDPs, Stateless persons, Others of concern.}
\item{\code{continent_origin}}{Continent of residence of population.}
\item{\code{n}}{Number of people concerned.}
}}
\source{
UNHCR (The UN Refugee Agency) (\url{https://www.unhcr.org/})
}