我正在尝试在闪亮的应用程序中显示导入的 pdf,下面是可重现的代码,但导入后 pdf 查看器是空白的,也没有显示任何错误。不知道如何让它工作。
library(tidyverse)
library(shiny)
library(pdftools)
ui <- fluidPage(
titlePanel("Demo"),
fileInput("file_import", "Upload Files", multiple = T, accept = ".pdf"),
tableOutput("files"),
uiOutput("pdfview")
)
server <- function(input, output, session) {
output$files <- renderTable({input$file_import})
observeEvent(input$file_import,{
output$pdfview <- renderUI({
tags$iframe(style = 'height: 680px; width: 960px;scrolling=yes',
src = input$file_import$datapath)
})
})
}
shinyApp(ui, server)
答案 0 :(得分:1)
以下工作正常。
library(shiny)
ui <- shinyUI(fluidPage(
titlePanel("Testing File upload"),
sidebarLayout(
sidebarPanel(
fileInput('file_input', 'upload file ( . pdf format only)', accept = c('.pdf'))
),
mainPanel(
uiOutput("pdfview")
)
)
))
server <- shinyServer(function(input, output) {
observe({
req(input$file_input)
file.copy(input$file_input$datapath,"www", overwrite = T)
output$pdfview <- renderUI({
tags$iframe(style="height:600px; width:100%", src="0.pdf")
})
})
})
shinyApp(ui = ui, server = server)
请确保您有一个 www
文件夹并重新启动 RStudio。它应该在浏览器中本地工作。然后尝试部署并测试它 - 在确保您保存 www
的文件夹下有一个 app.R
文件夹之后。