我想问一个关于使用rpivotTable
带有刷新调整的包的数据透视表的pdf下载的问题。
我非常接近我想要的,但只需要最后一步。
这是我的代码:
闪亮的应用程序:app.r:
library(rpivotTable)
library(shiny)
library(htmlwidgets)
list_to_string <- function(obj, listname) {
if (is.null(names(obj))) {
paste(listname, "=", list(obj) )
} else {
paste(listname, "=", list( obj ),
sep = "", collapse = ",")
}
}
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,"'")
}
})
paste(allvalues, collapse = ",")
})
pivotRefresh2 <- reactive({
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,"'")
}
})
paste(allvalues, collapse = ",")
})
PivotTable<-reactive({
rpivotTable(data=cars, onRefresh=htmlwidgets::JS("function(config) { Shiny.onInputChange('myPivotData', config); }"))
})
PivotTable2<-reactive({
rpivotTable(data=cars,
##### Replace "pivotRefresh2()" Here
writeLines(pivotRefresh2() )
)
})
output$mypivot = renderRpivotTable({
PivotTable()
})
output$report = downloadHandler(
filename<- function(){
paste("Demo_Data_Analysis",Sys.Date(),".pdf",sep = "")
},
content = function(file) {
src <- normalizePath('Apply.Rmd')
# temporarily switch to the temp dir, in case you do not have write
# permission to the current working directory
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, 'Apply.Rmd', overwrite = TRUE)
library(rmarkdown)
out <- render('Apply.Rmd', pdf_document())
file.rename(out, file)
},
contentType = 'application/pdf'
)
}
ui <- shinyUI(fluidPage(
fluidRow(column(6,verbatimTextOutput("pivotRefresh")),
column(6, rpivotTableOutput("mypivot") )),
downloadButton('report',"Download this plot")
)
)
shinyApp(ui = ui, server = server)
我对 pdf 的降价:Rmd:
---
title: "Untitled"
author: "Statistician"
date: "December 3, 2016"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r Time_Single, out.width = "500px"}
saveWidget( PivotTable2(), file= 'temp_Time_single123.html')
respivot123 = webshot::webshot('temp_Time_single123.html','my- screenshotime_single123.png')
knitr::include_graphics(respivot123)
```
数据透视表顶部的文本输出是rPivotTable
包的正确参数输入,所以我唯一需要做的就是将它们放入参数输入区域。我尝试writeLines()
但它不工作。
其他一切都已经设置好,唯一的问题是如何放置参数##### Replace "pivotRefresh2()" Here
!
太感谢了!
此致!