でPDFをダウンロードして表示するshinyapps.ioのアプリでウェブ上のいくつかのPDFを表示しようとしています。残念ながら、iframeをURLとともに使用する標準的な方法は、混在したコンテンツのセーフガード(pdfはhttp経由で提供される)のためオプションではありません。私は、可能なオプションは、URLからpdfsをダウンロードし、それらをローカルファイルからのiframeに表示することだと思うが、これをtempfile()
と動作させることはできない。Shiny
サンプルアプリ:
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput("url", "add a url"),
actionButton("button","hit the button"),
h5("use case - embed a pdf user guide in the app - embed as a local pdf or from web URL")
),
mainPanel(
tabsetPanel(
tabPanel("PDF",
htmlOutput("pdf")
)
)
)
)
)
server <- function(input, output, session) {
observeEvent(input$button, {
temp <- tempfile(fileext = ".pdf")
download.file(input$url, temp)
output$pdf <- renderUI({
tags$iframe(src=temp)
})
})
}
shinyApp(ui, server)
サンプルPDF:私は、ブラウザでこれを開くとhttp://www.pdf995.com/samples/pdf.pdf
私は、ブラウザのコンソールでエラーが出ます: のiframeがあるパネルでNot allowed to load local resource: file:///C:/Users/.../Local/Temp/Rtmp8subWX/file19403a2a2fc8.pdf
と何も。
shinyapps.ioにアップロードされた同様の試みも失敗し、404 Not Found
というエラーがpdfビューアに表示されます。
これは、shiny/shinyapps.ioが一時ファイルを処理する方法に問題があるとは思いますが、それを理解することはできません。ありがとう。