![](/img/trans.png)
[英]R: Print plot on webpage while posting data to REST API created using plumber
[英]R Plumber posting a PDF
我正在嘗試通過 R Plumber 通過 HTTP post 請求訪問 PDF,使用 tabulizer 包讀取它,並以 JSON 格式響應 PDF。 我通過 Postman 將 53kb PDF 發布到我的路線並收到錯誤:
normalizePath(path.expand(path), winslash, mustWork) 中的錯誤。
我的 R API 路由代碼如下:
#' @post /tab
#' @json
function(req){
library("tabulizer")
f <- req$postBody
extract_tables(f)
}
當我將 extract_tables() 函數與我正在使用的 PDF 的本地路徑一起使用時,它可以完美地用作獲取路由。
#' @get /tab
#' @json
function(){
library("tabulizer")
f <- "C:/Users/kelse/Desktop/Rscripts/Tessaract/table.pdf"
extract_tables(f)
}
有人知道如何通過 Plumber 發布 pdf 文件並在函數中訪問它嗎?
您可以嘗試使用@serializer 通過 HTTP 發布
#* @serializer contentType list(type="application/pdf")
#* @get /pdf
function(){
tmp <- tempfile()
pdf(tmp)
plot(1:10, type="b")
text(4, 8, "PDF from plumber!")
text(6, 2, paste("The time is", Sys.time()))
dev.off()
readBin(tmp, "raw", n=file.info(tmp)$size)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.