I am developing an app that helps to organize and visualize many PDF documents by topic/theme. I can upload and read a single PDF but I have difficulty in reading multiple PDF documents.
For single PDF document:
ui.R
---
fileInput('file1', 'Choose PDF File', accept=c('.pdf'))
---
server.R
--------
library(pdftools)
-------
mypdf<-reactive({
inFile <- input$file1
if (is.null(inFile)){
return(NULL)
}else{
pdf_text(inFile$datapath)
}
})
To upload multiple PDF files, I have to use multiple = TRUE in the ui.R portion of the code, but how can I read in all the uploaded files?
I realise this question is older, but i was looking for the same answer and build a minimal app to test the functionality. The question is fully covered by the other answer, but as always reproducible code helps us all to save time, so i decided to share my minimal testing app.
Reproducible app:
# creating sample files to upload
write.csv2(
x = "diff same",
file = "test.csv"
)
write.csv2(
x = "diffhere same",
file = "test2.csv"
)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput(
inputId = "files",
label = "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")
)
),
mainPanel(
tableOutput("contents")
)
)
)
server <- function(input, output) {
output$contents <- renderTable({
req(input$files)
upload = list()
for(nr in 1:length(input$files[, 1])){
upload[[nr]] <- read.csv(
file = input$files[[nr, 'datapath']]
)
}
return(upload)
})
}
shinyApp(ui, server)
The uploaded files can be read in a for loop like this
for(i in 1:length(input$files[,1])){
lst[[i]] <- read.csv(input$files[[i, 'datapath']])
}
This is an example for CSV files but you can do the same for pdf files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With