rpivotTable:shinyapp透视表的动态pdf下载,带有刷新的调整

rpivotTable:shinyapp透视表的动态pdf下载,带有刷新的调整,r,pdf,shiny,htmlwidgets,rpivottable,R,Pdf,Shiny,Htmlwidgets,Rpivottable,我想问一个关于使用带刷新调整的rpivotTable包下载pivot表的pdf的问题 我非常接近我想要的,但只需要最后一步 这是我的密码: 闪亮应用程序: 附录r: pivot表顶部的文本输出是rPivotTable包的正确参数输入,因此我只需要将它们放入参数输入区域。我尝试了writeLines(),但它不起作用 其他一切都已经设置好了,唯一的问题是如何将参数####替换为此处的“pivotRefresh2()” 非常感谢你 致以最良好的祝愿 我们的朋友打电话 如果我理解正确,do.call将

我想问一个关于使用带刷新调整的
rpivotTable
包下载pivot表的pdf的问题

我非常接近我想要的,但只需要最后一步

这是我的密码:

闪亮应用程序: 附录r:

pivot表顶部的文本输出是
rPivotTable
包的正确参数输入,因此我只需要将它们放入参数输入区域。我尝试了
writeLines()
,但它不起作用

其他一切都已经设置好了,唯一的问题是如何将参数
####替换为此处的“pivotRefresh2()”

非常感谢你

致以最良好的祝愿

我们的朋友打电话 如果我理解正确,
do.call
将是解决方案。我们不应该尝试将参数作为字符串化列表传递,而应该使用该列表。下面是我认为可以实现您的目标的代码。您将看到带有更改的注释,以将其插入整个示例中。我将
rp
指定为一个全局变量,这样您就可以确保所有组件都正常工作。您将要删除该分配,并将封闭的
观察
更改回
反应

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({
    items <- input$myPivotData[c("cols","rows","vals", "exclusions","aggregatorName", "rendererName")]

    # need to remove the outside list container
    #  for rows and cols
    #  did not test thoroughly but these seemed to be
    #  the only two that require this
    items$cols <- unlist(items$cols,recursive=FALSE)
    items$rows <- unlist(items$rows,recursive=FALSE)

    items
  })

  PivotTable<-reactive({
    rpivotTable(data=cars, onRefresh=htmlwidgets::JS("function(config) {  Shiny.onInputChange('myPivotData', config); }"))
  })


  ########## add this to demo ###############
  ### what we are getting ###################
  observe({str(pivotRefresh2())})

  ########## change this back to reactive ##
  PivotTable2<-observe({
    ### do ugly global assign ################
    ### after done with Shiny ################
    ### rp available to inspect ##############
    rp <<- do.call(rpivotTable,c(list(data=cars),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) 
库(rpivotTable)
图书馆(闪亮)
库(htmlwidgets)
列出我们的朋友要做的事
如果我理解正确,
do.call
将是解决方案。我们不应该尝试将参数作为字符串化列表传递,而应该使用该列表。下面是我认为可以实现您的目标的代码。您将看到带有更改的注释,以将其插入整个示例中。我将
rp
指定为一个全局变量,这样您就可以确保所有组件都正常工作。您将要删除该分配,并将封闭的
观察
更改回
反应

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({
    items <- input$myPivotData[c("cols","rows","vals", "exclusions","aggregatorName", "rendererName")]

    # need to remove the outside list container
    #  for rows and cols
    #  did not test thoroughly but these seemed to be
    #  the only two that require this
    items$cols <- unlist(items$cols,recursive=FALSE)
    items$rows <- unlist(items$rows,recursive=FALSE)

    items
  })

  PivotTable<-reactive({
    rpivotTable(data=cars, onRefresh=htmlwidgets::JS("function(config) {  Shiny.onInputChange('myPivotData', config); }"))
  })


  ########## add this to demo ###############
  ### what we are getting ###################
  observe({str(pivotRefresh2())})

  ########## change this back to reactive ##
  PivotTable2<-observe({
    ### do ugly global assign ################
    ### after done with Shiny ################
    ### rp available to inspect ##############
    rp <<- do.call(rpivotTable,c(list(data=cars),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) 
库(rpivotTable)
图书馆(闪亮)
库(htmlwidgets)

列表到字符串哇!!!它起作用了!非常感谢你!唯一需要更改的是更改
PivotTable2Wow!!!它起作用了!非常感谢你!唯一需要更改的是更改数据透视表2
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({
    items <- input$myPivotData[c("cols","rows","vals", "exclusions","aggregatorName", "rendererName")]

    # need to remove the outside list container
    #  for rows and cols
    #  did not test thoroughly but these seemed to be
    #  the only two that require this
    items$cols <- unlist(items$cols,recursive=FALSE)
    items$rows <- unlist(items$rows,recursive=FALSE)

    items
  })

  PivotTable<-reactive({
    rpivotTable(data=cars, onRefresh=htmlwidgets::JS("function(config) {  Shiny.onInputChange('myPivotData', config); }"))
  })


  ########## add this to demo ###############
  ### what we are getting ###################
  observe({str(pivotRefresh2())})

  ########## change this back to reactive ##
  PivotTable2<-observe({
    ### do ugly global assign ################
    ### after done with Shiny ################
    ### rp available to inspect ##############
    rp <<- do.call(rpivotTable,c(list(data=cars),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)