I am Looking at this Question: displaying a pdf from a local drive in shiny and want to Display a local pdf file.
I placed my pdf within C:\Users\user1\Documents\shiny_pdf\www
. The app is placed in C:\Users\user1\Documents\shiny_pdf
and i set my working Directory to the latter Directory.
Now i am unsure on how to reference that file within the app.
The author of the answer post in the linked Question states:
so you have to save them in your www directory (a local web server) and access to files with their http(s): URLs (the URL will be something like http://localhost/.../mypdf.pdf)
So i am unsure on how to navigate from http://localhost/
to C:\Users\user1\Documents\shiny_pdf\www
.
What i tried:
I would have assumed i have
www
is the Server Directory so i would usehttp://localhost/R-intro.pdf
.I added an Image to my shiny app and checked its server address in the browser. Then i located the pdf file accordingly. I can open it via:
http://127.0.0.1:6023/r-intro.pdf
(with 6023 being my port number). But i cant use that either to reference it in the iframe.I also tried
list.files()
, but that would (obv.) give me the files from the working Directory.http://localhost/R-intro.pdf
also does not work.
The error:
Fehler: Verbindung fehlgeschlagen Firefox kann keine Verbindung zu dem Server unter localhost aufbauen.
which loosely translates to. Connection failed. Firefox can“t make a Connection to the Server under localhost.
Reproducible Code:
Save the following file (see below) as, e.g.
app.R
.Run the following Code to create a WWW directoy for shiny and place a sample pdf into it.
dir.create("www")
pdf(file = "www/r-intro.pdf")
plot(1)
dev.off()
list.files()
Here the Code to save in e.g. app.R
.
Code:
library(shiny)
server <- shinyServer(function(input, output, session) {
observe({
print(list.files("http://localhost/R-intro.pdf"))
})
output$pdfviewer <- renderText({
return(paste('<iframe style="height:600px; width:100%" src="', input$pdfurl, '"></iframe>', sep = ""))
})
})
row <- function(...) {
tags$div(class="row", ...)
}
col <- function(width, ...) {
tags$div(class=paste0("span", width), ...)
}
ui <- shinyUI(bootstrapPage(
headerPanel("PDF VIEWER"),
mainPanel(
tags$div(
class = "container",
row(
col(3, textInput("pdfurl", "PDF URL"))
),
row(
col(6, htmlOutput('pdfviewer')),
col(6, tags$iframe(style="height:600px; width:100%", src="https://localhost/www/R-intro.pdf"))
)
)
)
))
shinyApp(ui, server)