R &引用;闪亮应用程序“;上载文件->;做某事->;输出文件 我正在尝试编写我的第一个闪亮的应用程序,它可以读取PDF文件、提取表格并将其保存到Excel文档中。

R &引用;闪亮应用程序“;上载文件->;做某事->;输出文件 我正在尝试编写我的第一个闪亮的应用程序,它可以读取PDF文件、提取表格并将其保存到Excel文档中。,r,web-scraping,shiny,R,Web Scraping,Shiny,我无法生成合适的代码。到目前为止,我已经: 1) 用于用户界面 2) 对于服务器 library(shiny) library (tabulizer) library(writexl) shinyServer(function(input, output) { data <- reactive({ file1 <- input$file if(is.null(file1)){return()} file1 <- ExtractT

我无法生成合适的代码。到目前为止,我已经: 1) 用于用户界面

2) 对于服务器

library(shiny)
library (tabulizer)
library(writexl) 

shinyServer(function(input, output) {       
    data <- reactive({
    file1 <- input$file
    if(is.null(file1)){return()}
    file1 <- ExtractTable (file1)        
})
## Download
output$dl <- downloadHandler(
  filename = function() { "ae.xlsx"}, 
  content = function(file) {write_xlsx(data, path = file)}  
)    
})
库(闪亮)
图书馆(tabulizer)
图书馆(writexl)
shinyServer(函数(输入、输出){
数据你能试试:

shinyServer(function(input, output) {       
    data <- reactive({
    file1 <- input$file
    if(is.null(file1)){return()}
    ExtractTable(file1$datapath) # $datapath was missing       
})
## Download
output$dl <- downloadHandler(
  filename = function() { "ae.xlsx"}, 
  content = function(file) {write_xlsx(data(), path = file)} # parentheses () were missing
)    
})
shinyServer(函数(输入、输出){

数据感谢您的回复。不幸的是,通过这段代码我得到了:警告:路径错误。扩展:无效的“路径”参数[没有可用的堆栈跟踪]警告:写入错误\u xlsx:参数x必须是数据帧或数据帧列表[没有可用的堆栈跟踪]我尝试了一个更简单的例子,将ExtractFunction替换为:DOSOMETHING它甚至不适用于上传一个csv文件并将其保存到excel:(警告:write_xlsx中出错:参数x必须是数据帧或数据帧列表[No stack trace available]shinyServer(函数(输入、输出){数据@ GuStavoSaveBar PalFox有括号:<代码> Read EXXLSX(DATA(),PATH =文件)<代码>(<代码>数据())/代码>,不是<代码>数据< /代码>?我尝试有和没有PARE.NTESION。如果我写DF= MTCAS,然后写DF而不是DATA()在write_xlsx中,我成功地将mtcars输出为excel。但我无法简单地读取csv文件,将其存储在变量中并输出为excel:(
ExtractTable <- function (report){
  lst <- extract_tables(report, encoding="UTF-8") 

  # Delete blank columns
  lst[[1]] <- lst[[1]][, -3]
  lst[[2]] <- lst[[2]][, -4]

  # Bind the list elements 
  table <- do.call(rbind, lst)
  table <- as.data.frame(table[c(2:37, 40:nrow(table)), ],
                         stringsAsFactors=FALSE) # ...w/o obsolete rows

  # Take over colnames, cache rownames to vector
  colnames(table) <- table[1, ]
  rn <- table[2:71, 1]
  table <- table[-1,-1] # and bounce them out of the table

  #  Coerce to numeric 
  table <- as.data.frame(apply(table[1:70,1:10], 2, 
                               function(x) as.numeric(as.character(x))))
  rownames(table) <- rn 

  return(table)

}
shinyServer(function(input, output) {       
    data <- reactive({
    file1 <- input$file
    if(is.null(file1)){return()}
    ExtractTable(file1$datapath) # $datapath was missing       
})
## Download
output$dl <- downloadHandler(
  filename = function() { "ae.xlsx"}, 
  content = function(file) {write_xlsx(data(), path = file)} # parentheses () were missing
)    
})