Description Usage Arguments Value Examples
View source: R/dashPivotTable.R
Pivot tables are useful for interactive presentation of summary statistics computed for data contained in another table. This function provides a convenient Dash interface to the 'react-pivottable' component, which makes it easy to embed pivot tables into Dash for R applications. Within React, the interactive component provided by 'react-pivottable' is 'PivotTableUI', but output rendering is delegated to the non-interactive 'PivotTable' component, which accepts a subset of its properties. 'PivotTable' in turn delegates to a specific renderer component, such as the default 'TableRenderer', which accepts a subset of the same properties. Finally, most renderers will create non-React PivotData objects to handle the actual computations, which also accept a subset of the same properties as the rest of the stack. The arguments for this function correspond to properties of the component; a full list is provided below. 'react-pivottable' was developed by Nicolas Kruchten; source for this component is available from https://github.com/plotly/react-pivottable.
1 2 3 4 5 6 |
id |
Character. The ID used to identify this component in Dash callbacks |
data |
Unnamed list. Data to be summarized |
hiddenAttributes |
Unnamed list. Specifies attribute names to omit from the UI |
hiddenFromAggregators |
Unnamed list. Specifies attribute names to omit from the aggregator arguments dropdowns |
hiddenFromDragDrop |
Unnamed list. Specifies attribute names to omit from the drag and drop portion of the UI |
menuLimit |
Numeric. Maximum number of values to list in the double-click menu |
unusedOrientationCutoff |
Numeric. If the attributes' names' combined length in characters exceeds this value then the unused attributes area will be shown vertically to the left of the UI instead of horizontally above it. 0 therefore means 'always vertical', and infinity means 'always horizontal'. |
cols |
Unnamed list. Specifies which columns are currently in the column area |
colOrder |
Character. The order in which column data is provided to the renderer, must be one of "key_a_to_z", "value_a_to_z", "value_z_to_a", ordering by value orders by column total |
rows |
Unnamed list. Specifies which rows are currently inside the row area. |
rowOrder |
Character. The order in which row data is provided to the renderer, must be one of "key_a_to_z", "value_a_to_z", "value_z_to_a", ordering by value orders by row total |
aggregatorName |
Character. Specifies which aggregator is currently selected. e.g. Count, Sum, Average, etc. |
vals |
Unnamed list. Values to use for the aggregator. |
valueFilter |
Named list. Value filter for each attibute name. |
rendererName |
Character. Specifies which renderer is currently selected. e.g. Table, Line Chart, Scatter Chart, etc. |
named list of JSON elements corresponding to React.js properties and their values
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | # Input data for dashPivottable may be passed in the "list-of-lists"
# format -- scroll down to see an example which demonstrates how
# to pass a data.frame into dashPivottable directly.
if (interactive() && require(dash)) {
library(dash)
library(dashPivottable)
library(dashHtmlComponents)
app <- Dash$new()
app$title("Summary statistics for tips data")
app$layout(
htmlDiv(
list(
dashPivotTable(
id = "table",
data = tips,
cols = list("Day of Week"),
colOrder = "key_a_to_z",
rows = list("Party Size"),
rowOrder = "key_a_to_z",
rendererName = "Grouped Column Chart",
aggregatorName = "Average",
vals = list("Total Bill"),
valueFilter = list("Day of Week"=list("Thursday"=FALSE))
),
htmlDiv(
id = "output"
)
)
)
)
app$callback(output = output(id="output", property="children"),
params = list(input(id="table", property="cols"),
input(id="table", property="rows"),
input(id="table", property="rowOrder"),
input(id="table", property="colOrder"),
input(id="table", property="aggregatorName"),
input(id="table", property="rendererName")),
function(cols, rows, row_order, col_order, aggregator, renderer) {
return(
list(
htmlP(cols, id="columns"),
htmlP(rows, id="rows"),
htmlP(row_order, id="row_order"),
htmlP(col_order, id="col_order"),
htmlP(aggregator, id="aggregator"),
htmlP(renderer, id="renderer")
)
)
}
)
app$run_server(debug=TRUE)
# This example illustrates the use of `df_to_list` to format a data.frame
# for use with dashPivottable
library(dashTable)
app <- Dash$new()
app$title("Summary statistics for iris data")
app$layout(
htmlDiv(
list(
dashPivotTable(
id = "table",
data = df_to_list(Loblolly),
cols = list("Seed"),
colOrder = "key_a_to_z",
rows = list("age"),
rowOrder = "key_a_to_z",
rendererName = "Grouped Column Chart",
aggregatorName = "Average",
vals = list("height")
),
htmlDiv(
id = "output"
)
)
)
)
app$callback(output = output(id="output", property="children"),
params = list(input(id="table", property="cols"),
input(id="table", property="rows"),
input(id="table", property="rowOrder"),
input(id="table", property="colOrder"),
input(id="table", property="aggregatorName"),
input(id="table", property="rendererName")),
function(cols, rows, row_order, col_order, aggregator, renderer) {
return(
list(
htmlP(cols, id="columns"),
htmlP(rows, id="rows"),
htmlP(row_order, id="row_order"),
htmlP(col_order, id="col_order"),
htmlP(aggregator, id="aggregator"),
htmlP(renderer, id="renderer")
)
)
}
)
app$run_server(debug=TRUE)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.