The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial. If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
Getting started
Introduction
The kpiwidget package provides an easy way to create KPI
(Key Performance Indicator) widgets for dashboards using
crosstalk shared data. This vignette demonstrates different
options and functionalities available in kpiwidget.
Installation
Before using kpiwidget, ensure that it is installed
along with crosstalk:
# install.packages("crosstalk")# Install kpiwidget from CRAN or GitHub# install.packages("kpiwidget")# devtools::install_github("your_github/kpiwidget")
Loading Required Libraries
library(kpiwidget)library(crosstalk)library(DT)library(dplyr)#> #> Attaching package: 'dplyr'#> The following objects are masked from 'package:stats':#> #> filter, lag#> The following objects are masked from 'package:base':#> #> intersect, setdiff, setequal, unionlibrary(htmltools)
Creating a Shared Data Object
To enable interactivity, we first wrap our dataset in
SharedData from crosstalk. This allows
filtering across multiple widgets using the same dataset.
# Create a shared data object with row numbers as keysdf_shared <- crosstalk::SharedData$new(mtcars, key =~1:nrow(mtcars), group ="mtcars_group")
Adding Filters
crosstalk allows dynamic filtering of data. Here, we add
a filter to select vehicles based on the number of gears:
The kpiwidget function provides a simple way to display
key performance indicators. The column parameter is
required, and by default, it calculates the count (number of rows in the
dataset).
kpi - A character string specifying the metric to compute. Options:
count, distinctCount, duplicates, sum, mean, min, max. Default is
count.
comparison - A character string indicating a comparison mode.
Options are ratio or share. Default is NULL.
column - A column name (as a string) to be used for numeric
aggregation. Default is NULL, this parameter is REQUIRED.
selection - A one-sided formula. Serves as a global filter. Default
is NULL.
group1 - For comparison mode: a one-sided formula defining group 1.
This is required in comparison mode. Default is NULL.
group2 - For comparison mode: a one-sided formula defining group 2.
For comparison = “ratio”, if not provided, it defaults to the complement
of group1. For comparison = “share”, if not provided, it defaults to all
rows. Default is NULL.
decimals - Number of decimals to round the computed result. Default
is 1.
big_mark - Character to be used as the thousands separator. Default
is ” “.
prefix - A string to be prepended to the displayed value. Default is
NULL.
suffix - A string to be appended to the displayed value. Default is
NULL.
width - Widget width (passed to htmlwidgets::createWidget). Default
is NULL.
height - Widget height (passed to htmlwidgets::createWidget).
Default is NULL.
elementId - Optional element ID for the widget. Default is
NULL.
group - Crosstalk group name. Typically provided by the SharedData
object. Default is NULL.
KPI Options
The kpi parameter allows different types of
calculations. Below, we demonstrate various options available in
kpiwidget.
Calculates the ratio of a subset defined with group1
parameter (e.g., cars with 4 cylinders) compared to the complement of
group1 filter (default setting for “ratio”) or to the subset defined
with group2 parameter.
On average they have
and can drive
8 cylinder cars have
times more HP than the rest of cars in selection.
Conclusion
The kpiwidget package provides a flexible way to display
KPIs in interactive dashboards. Using crosstalk, it enables
real-time filtering and comparison of data.
These binaries (installable software) and packages are in development. They may not be fully stable and should be used with caution. We make no claims about them. Health stats visible at Monitor.