I\'ve found an interesting package rpivotTable.
I\'d like to create shiny app which includes rpivotTable with the possibility to downl
I've just pushed on the master branch of rpivotTable on github a change that addresses the issue of getting the parameters the user is / has looked at on the server side.
Download the rpivotTable code with devtools:
devtools::install_github("smartinsightsfromdata/rpivotTable",ref="master")
This is an example of how to get the selected data on the server side. The example is not complete for your needs: you need to subset the original data frame with what you get back from rpivotTable. But this should be enough to give you an head start.
library(rpivotTable)
library(shiny)
list_to_string <- function(obj, listname) {
if (is.null(names(obj))) {
paste(listname, "[[", seq_along(obj), "]] = ", obj,
sep = "", collapse = "\n")
} else {
paste(listname, "$", names(obj), " = ", obj,
sep = "", collapse = "\n")
}
}
server <- function(input, output) {
output$pivotRefresh <- renderText({
cnames <- list("cols","rows","vals", "exclusions","aggregatorName", "rendererName")
# Apply a function to all keys, to get corresponding values
allvalues <- lapply(cnames, function(name) {
item <- input$myPivotData[[name]]
if (is.list(item)) {
list_to_string(item, name)
} else {
paste(name, item, sep=" = ")
}
})
paste(allvalues, collapse = "\n")
})
output$mypivot = renderRpivotTable({
rpivotTable(data=cars, onRefresh=htmlwidgets::JS("function(config) { Shiny.onInputChange('myPivotData', config); }"))
})
}
ui <- shinyUI(fluidPage(
fluidRow(column(6, verbatimTextOutput("pivotRefresh")),
column(6, rpivotTableOutput("mypivot") ))
)
)
shinyApp(ui = ui, server = server)