I've found an interesting package rpivotTable
.
I'd like to create shiny app
which includes rpivotTable
with the possibility to download generated data using downloadHandler
.
However, I am unable to find the solution, how to create data.frame
or something else which I'd be able to pass to the downloadHandler
function.
rpivotTable
creates an object of class:
class(pivot)
[1] "rpivotTable" "htmlwidget"
Is threne any possibilities to download the output of the this function?
Also, I enclose the example, how the pivot is created in shiny and the example of download function which I'd like to use.
Maybe are the any other ideas or suggestions?
set.seed(1992)
n=99
Year <- sample(2013:2015, n, replace = TRUE, prob = NULL)
Month <- sample(1:12, n, replace = TRUE, prob = NULL)
Category <- sample(c("Car", "Bus", "Bike"), n, replace = TRUE, prob = NULL)
Brand <- sample("Brand", n, replace = TRUE, prob = NULL)
Brand <- paste0(Brand, sample(1:14, n, replace = TRUE, prob = NULL))
USD <- abs(rnorm(n))*100
df <- data.frame(Year, Month, Category, Brand, USD)
output$Pivot <- rpivotTable::renderRpivotTable({
rpivotTable(data = df, rows = "Brand", col = "Category", vals = "USD", aggregatorName = "Sum", rendererName = "Table")
})
output$downloadData <- downloadHandler(
filename = function() { paste(filename, '.csv', sep='') },
content = function(file) {
write.csv(PivotOutput, file)
})