我在 Shiny 应用程序中使用 rpivotTable 包,我只想为用户选择“表”(无图表)
RenderName 参数仅用于选择默认显示...
output$pivot <- renderRpivotTable(
rpivotTable(iris,
rendererName = "Table" )
)
提前谢谢了 !
我在 Shiny 应用程序中使用 rpivotTable 包,我只想为用户选择“表”(无图表)
RenderName 参数仅用于选择默认显示...
output$pivot <- renderRpivotTable(
rpivotTable(iris,
rendererName = "Table" )
)
提前谢谢了 !
这里有多个问题。
renderers
. rpivotTable()
我这里有 JS 代码表格。rpivotTable()
再次将参数包装在列表中(参见Map()
原始函数代码中的调用),转发到 JS 失败。因此,我考虑了这个问题并稍微扩展了功能。玩弄聚合器/渲染器,看看它的行为与原始rpivotTable()
函数有何不同。
# define own function
my_rpivotTable <- function (data, rows = NULL, cols = NULL, aggregatorName = NULL,
vals = NULL, rendererName = NULL, sorter = NULL, exclusions = NULL,
inclusions = NULL, locale = "en", subtotals = FALSE, ...,
width = 800, height = 600, elementId = NULL)
{
if (length(intersect(class(data), c("data.frame", "data.table",
"table", "structable", "ftable"))) == 0) {
stop("data should be a data.frame, data.table, or table",
call. = F)
}
if (length(intersect(c("table", "structable", "ftable"),
class(data))) > 0)
data <- as.data.frame(data)
params <- list(rows = rows, cols = cols, aggregatorName = aggregatorName,
vals = vals, rendererName = rendererName, sorter = sorter,
...)
params <- Map(function(p) {
# added to the class check -------------------------------------------------
if (length(p) == 1 && class(p[[1]]) != "JS_EVAL") {
p = list(p)
}
return(p)
}, params)
par <- list(exclusions = exclusions, inclusions = inclusions)
params <- c(params, par)
params <- Filter(Negate(is.null), params)
x <- list(data = data, params = params, locale = locale,
subtotals = subtotals)
htmlwidgets::createWidget(name = "rpivotTable", x, width = width,
height = height, elementId = elementId, package = "rpivotTable")
}
# create the pivot table
my_rpivotTable(
expand.grid(LETTERS, 1:3),
aggregatorName = "Count",
aggregators = list(Sum = htmlwidgets::JS('$.pivotUtilities.aggregators["Sum"]'),
Count = htmlwidgets::JS('$.pivotUtilities.aggregators["Count"]')),
rendererName = "fancyTable",
renderers = list(fancyTable = htmlwidgets::JS('$.pivotUtilities.renderers["Table"]'))
)