I am looking to build a Shiny app where users can select a pdf file (with some extra info), which is then displayed in-app.
I was able to pull up a pdf from files placed in the app's www/
directory, as detailed here.
Below is my demo app. To run this, make a directory www/reports/
next to your app.R
and place 3 pdfs in there named report1.pdf
, report2.pdf
and report3.pdf
. Or download my project folder here. Run the app in the browser to see the full pdf viewer.
library(shiny)
ui <- fluidPage(
selectInput("select_pdf", "Select PDF file", choices = c("report1.pdf", "report2.pdf", "report3.pdf")),
actionButton("btn_view_pdf", "View PDF"),
htmlOutput("pdfviewer")
)
server <- function(input, output) {
# Construct pdf filepath on button click
pdf_filepath <- eventReactive(input$btn_view_pdf, {
pdf_dir <- "reports"
file.path(pdf_dir, input$select_pdf)
})
# Show PDF in iframe
output$pdfviewer <- renderText({
paste('<iframe style="height:1000px; width:50%" src="', pdf_filepath(), '"></iframe>', sep = "")
})
}
shinyApp(ui = ui, server = server)
While this works nicely, it is not enough for my purpose. The pdfs I want to show currently live on our company HPC server, and there are thousands of pdfs, i.e. I can't copy all of them into the www/
directory inside my shiny app.
Is there a way to 1) directly fetch the pdfs from the company server and 2) feed them into the iframe? I have credentials to access the company server file tree (via ssh) and could probably put them into environment variables on the server that hosts the shiny app.
Can you point me to any best practices, resources or packages for this? I thought this is a common thing to do, but I am not finding much info out there. Thanks!