fixed r cmd check
This commit is contained in:
parent
88956c582b
commit
47ef3d1b3e
|
@ -15,6 +15,7 @@ LazyData: true
|
|||
ByteCompile: true
|
||||
Depends: R (>= 2.10)
|
||||
Imports:
|
||||
htmltools,
|
||||
htmlwidgets,
|
||||
magrittr,
|
||||
rlang,
|
||||
|
|
11
NAMESPACE
11
NAMESPACE
|
@ -17,6 +17,7 @@ export(apex)
|
|||
export(apexchart)
|
||||
export(apexchartOutput)
|
||||
export(apexchartProxy)
|
||||
export(apexfacetOutput)
|
||||
export(ax_annotations)
|
||||
export(ax_chart)
|
||||
export(ax_colors)
|
||||
|
@ -59,6 +60,7 @@ export(parse_df)
|
|||
export(pie_opts)
|
||||
export(radialBar_opts)
|
||||
export(renderApexchart)
|
||||
export(renderApexfacet)
|
||||
export(renderSparkBox)
|
||||
export(run_demo_input)
|
||||
export(run_demo_sparkbox)
|
||||
|
@ -74,8 +76,13 @@ export(vars)
|
|||
importFrom(ggplot2,aes)
|
||||
importFrom(ggplot2,label_value)
|
||||
importFrom(ggplot2,vars)
|
||||
importFrom(htmltools,renderTags)
|
||||
importFrom(htmltools,resolveDependencies)
|
||||
importFrom(htmltools,tagList)
|
||||
importFrom(htmltools,tags)
|
||||
importFrom(htmlwidgets,JS)
|
||||
importFrom(htmlwidgets,createWidget)
|
||||
importFrom(htmlwidgets,getDependency)
|
||||
importFrom(htmlwidgets,shinyRenderWidget)
|
||||
importFrom(htmlwidgets,shinyWidgetOutput)
|
||||
importFrom(htmlwidgets,sizingPolicy)
|
||||
|
@ -90,9 +97,13 @@ importFrom(rlang,is_null)
|
|||
importFrom(rlang,quos)
|
||||
importFrom(rlang,sym)
|
||||
importFrom(rlang,syms)
|
||||
importFrom(shiny,createRenderFunction)
|
||||
importFrom(shiny,createWebDependency)
|
||||
importFrom(shiny,exprToFunction)
|
||||
importFrom(shiny,getDefaultReactiveDomain)
|
||||
importFrom(shiny,registerInputHandler)
|
||||
importFrom(shiny,shinyAppFile)
|
||||
importFrom(shiny,uiOutput)
|
||||
importFrom(stats,complete.cases)
|
||||
importFrom(stats,lm)
|
||||
importFrom(stats,loess)
|
||||
|
|
47
R/facets.R
47
R/facets.R
|
@ -103,7 +103,6 @@ build_facets <- function(chart) {
|
|||
facet <- facets_data[[i]]
|
||||
if (!is_null(labeller) && is_function(labeller)) {
|
||||
keys <- attr(facet, "keys")
|
||||
# browser()
|
||||
new <- ax_title(new, text = labeller(keys))
|
||||
}
|
||||
mapdata <- lapply(chart$x$mapping, eval_tidy, data = facet)
|
||||
|
@ -150,13 +149,14 @@ get_last_row <- function(mat) {
|
|||
})
|
||||
}
|
||||
|
||||
#' @importFrom htmltools tags
|
||||
build_grid <- function(content, nrow = NULL, ncol = NULL, col_gap = "0px", row_gap = "10px") {
|
||||
d <- get_grid_dims(content, nrow, ncol)
|
||||
htmltools::tags$div(
|
||||
tags$div(
|
||||
class = "apexcharter-facet-container",
|
||||
style = "display: grid;",
|
||||
style = sprintf("grid-template-columns: repeat(%s, 1fr);", d$ncol),
|
||||
style = sprintf("grid-template-rows: repeat(%s, 1fr);", d$nrow),
|
||||
style = "display:-ms-grid; display: grid;",
|
||||
style = sprintf("-ms-grid-columns: repeat(%1$s, 1fr); grid-template-columns: repeat(%1$s, 1fr);", d$ncol),
|
||||
style = sprintf("-ms-grid-rows: repeat(%1$s, 1fr); grid-template-rows: repeat(%1$s, 1fr);", d$nrow),
|
||||
style = sprintf("grid-column-gap: %s;", col_gap),
|
||||
style = sprintf("grid-row-gap: %s;", row_gap),
|
||||
content
|
||||
|
@ -170,6 +170,9 @@ build_grid <- function(content, nrow = NULL, ncol = NULL, col_gap = "0px", row_g
|
|||
#' @param ax An \code{apexcharts} \code{htmlwidget} object.
|
||||
#' @param facets Variable(s) to use for facetting, wrapped in \code{vars(...)}.
|
||||
#' @param nrow,ncol Number of row and column in output matrix.
|
||||
#' @param scales Should scales be fixed (\code{"fixed"}, the default),
|
||||
#' free (\code{"free"}), or free in one dimension (\code{"free_x"}, \code{"free_y"})?
|
||||
#' @param labeller A function with one argument containing for each facet the value of the faceting variable.
|
||||
#' @param chart_height Individual chart height.
|
||||
#'
|
||||
#' @return An \code{apexcharts} \code{htmlwidget} object.
|
||||
|
@ -177,7 +180,7 @@ build_grid <- function(content, nrow = NULL, ncol = NULL, col_gap = "0px", row_g
|
|||
#'
|
||||
#' @importFrom rlang quos syms
|
||||
#'
|
||||
#' @examples
|
||||
#' @example examples/facet_wrap.R
|
||||
ax_facet_wrap <- function(ax,
|
||||
facets,
|
||||
nrow = NULL,
|
||||
|
@ -208,16 +211,40 @@ ax_facet_wrap <- function(ax,
|
|||
|
||||
# Shiny -------------------------------------------------------------------
|
||||
|
||||
|
||||
#' @title Shiny bindings for faceting with apexcharter
|
||||
#'
|
||||
#' @description Output and render functions for using apexcharter faceting within Shiny
|
||||
#' applications and interactive Rmd documents.
|
||||
#'
|
||||
#' @param outputId output variable to read from
|
||||
#'
|
||||
#' @return An Apexcharts output that can be included in the application UI.
|
||||
#' @export
|
||||
#'
|
||||
#' @name apexcharter-shiny-facets
|
||||
#'
|
||||
#' @importFrom htmltools tagList
|
||||
#' @importFrom shiny uiOutput
|
||||
#' @importFrom htmlwidgets getDependency
|
||||
#'
|
||||
#' @example examples/facet-shiny.R
|
||||
apexfacetOutput <- function(outputId) {
|
||||
htmltools::tagList(
|
||||
shiny::uiOutput(outputId = outputId),
|
||||
htmlwidgets::getDependency("apexcharter", "apexcharter")
|
||||
tagList(
|
||||
uiOutput(outputId = outputId),
|
||||
getDependency(name = "apexcharter", package = "apexcharter")
|
||||
)
|
||||
}
|
||||
|
||||
#' @param expr An expression that generates a apexcharter
|
||||
#' @param env The environment in which to evaluate \code{expr}.
|
||||
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
|
||||
#' is useful if you want to save an expression in a variable.
|
||||
#'
|
||||
#' @export
|
||||
#'
|
||||
#' @rdname apexcharter-shiny-facets
|
||||
#'
|
||||
#' @importFrom shiny exprToFunction createRenderFunction createWebDependency
|
||||
#' @importFrom htmltools renderTags resolveDependencies
|
||||
renderApexfacet <- function(expr, env = parent.frame(), quoted = FALSE) {
|
||||
|
@ -229,7 +256,7 @@ renderApexfacet <- function(expr, env = parent.frame(), quoted = FALSE) {
|
|||
return(NULL)
|
||||
if (!inherits(result, "apex_facet")) {
|
||||
stop(
|
||||
"renderApexfacet: 'expr' must return an apexcharter facets.",
|
||||
"renderApexfacet: 'expr' must return an apexcharter facet object.",
|
||||
call. = FALSE
|
||||
)
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ server <- function(input, output, session) {
|
|||
|
||||
}
|
||||
|
||||
shinyApp(ui, server)
|
||||
if (interactive())
|
||||
shinyApp(ui, server)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/facets.R
|
||||
\name{apexcharter-shiny-facets}
|
||||
\alias{apexcharter-shiny-facets}
|
||||
\alias{apexfacetOutput}
|
||||
\alias{renderApexfacet}
|
||||
\title{Shiny bindings for faceting with apexcharter}
|
||||
\usage{
|
||||
apexfacetOutput(outputId)
|
||||
|
||||
renderApexfacet(expr, env = parent.frame(), quoted = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{outputId}{output variable to read from}
|
||||
|
||||
\item{expr}{An expression that generates a apexcharter}
|
||||
|
||||
\item{env}{The environment in which to evaluate \code{expr}.}
|
||||
|
||||
\item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This
|
||||
is useful if you want to save an expression in a variable.}
|
||||
}
|
||||
\value{
|
||||
An Apexcharts output that can be included in the application UI.
|
||||
}
|
||||
\description{
|
||||
Output and render functions for using apexcharter faceting within Shiny
|
||||
applications and interactive Rmd documents.
|
||||
}
|
||||
\examples{
|
||||
|
||||
library(shiny)
|
||||
library(htmltools)
|
||||
library(apexcharter)
|
||||
|
||||
data("unhcr_ts")
|
||||
refugees <- unhcr_ts \%>\%
|
||||
subset(population_type == "Refugees (incl. refugee-like situations)") \%>\%
|
||||
transform(date = as.Date(paste0(year, "-01-01")))
|
||||
|
||||
|
||||
ui <- fluidPage(
|
||||
|
||||
tags$h2("Apexcharts Facets Example"),
|
||||
|
||||
apexfacetOutput("myfacet")
|
||||
|
||||
)
|
||||
|
||||
server <- function(input, output, session) {
|
||||
|
||||
output$myfacet <- renderApexfacet({
|
||||
apex(refugees, aes(date, n), type = "line") \%>\%
|
||||
ax_yaxis(tickAmount = 5) \%>\%
|
||||
ax_facet_wrap(vars(continent_origin))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
if (interactive())
|
||||
shinyApp(ui, server)
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -21,6 +21,11 @@ ax_facet_wrap(
|
|||
|
||||
\item{nrow, ncol}{Number of row and column in output matrix.}
|
||||
|
||||
\item{scales}{Should scales be fixed (\code{"fixed"}, the default),
|
||||
free (\code{"free"}), or free in one dimension (\code{"free_x"}, \code{"free_y"})?}
|
||||
|
||||
\item{labeller}{A function with one argument containing for each facet the value of the faceting variable.}
|
||||
|
||||
\item{chart_height}{Individual chart height.}
|
||||
}
|
||||
\value{
|
||||
|
@ -28,4 +33,79 @@ An \code{apexcharts} \code{htmlwidget} object.
|
|||
}
|
||||
\description{
|
||||
Facet wrap for ApexCharts
|
||||
}
|
||||
\examples{
|
||||
library(apexcharter)
|
||||
|
||||
# Scatter ----
|
||||
|
||||
data("mpg", package = "ggplot2")
|
||||
|
||||
# Create facets
|
||||
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
||||
ax_facet_wrap(vars(drv))
|
||||
|
||||
# Change number of columns
|
||||
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
||||
ax_facet_wrap(vars(drv), ncol = 2)
|
||||
|
||||
# Free axis
|
||||
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
||||
ax_facet_wrap(vars(drv), ncol = 2, scales = "free")
|
||||
|
||||
# labels
|
||||
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
||||
ax_facet_wrap(
|
||||
vars(drv), ncol = 2,
|
||||
labeller = function(x) {
|
||||
switch(
|
||||
x,
|
||||
"f" = "front-wheel drive",
|
||||
"r" = "rear wheel drive",
|
||||
"4" = "4wd"
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# Multiple variables
|
||||
|
||||
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
||||
ax_facet_wrap(vars(year, drv))
|
||||
|
||||
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
||||
ax_facet_wrap(
|
||||
vars(year, drv),
|
||||
labeller = function(x) {
|
||||
paste(x, collapse = " / ")
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Lines ----
|
||||
|
||||
data("unhcr_ts")
|
||||
refugees <- unhcr_ts \%>\%
|
||||
subset(population_type == "Refugees (incl. refugee-like situations)") \%>\%
|
||||
transform(date = as.Date(paste0(year, "-01-01")))
|
||||
|
||||
|
||||
apex(refugees, aes(date, n), type = "line") \%>\%
|
||||
ax_yaxis(tickAmount = 5) \%>\%
|
||||
ax_facet_wrap(vars(continent_origin))
|
||||
|
||||
|
||||
|
||||
# Free y-axis and synchronize
|
||||
apex(refugees, aes(date, n), type = "line", synchronize = "my-id") \%>\%
|
||||
ax_yaxis(tickAmount = 5) \%>\%
|
||||
ax_xaxis(tooltip = list(enabled = FALSE)) \%>\%
|
||||
ax_tooltip(x = list(format = "yyyy")) \%>\%
|
||||
ax_facet_wrap(vars(continent_origin), scales = "free_y")
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue