我发现了一个有趣的包rpivotTable
。我想创建shiny app
其中包括rpivotTable
使用downloadHandler
.
但是,我无法找到解决方案、如何创建data.frame
或其他我能够传递给downloadHandler
函数的东西。
rpivotTable
创建一个类对象:
class(pivot)
[1] "rpivotTable" "htmlwidget"
threne 是否有可能下载此函数的输出?
另外,我附上了示例,如何在闪亮中创建枢轴以及我想使用的下载功能示例。
也许还有其他想法或建议?
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)
})