r - r闪亮的pdf显示为空白
问题描述
我正在尝试在闪亮的应用程序中显示导入的 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)
解决方案
以下工作正常。
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
.
推荐阅读
- sql - 通过 SQL Server 存储过程调度作业
- linux - MongoDB 不运行
- django - 使用加密和散列电子邮件作为用户名的 Django 用户模型
- python - 更改可变属性会更改类的每个实例中的该属性
- javascript - 如何在循环内声明类副本
- yaml - YAML - 获取有关新 yaml 属性的数据
- mongodb - MongoDB 平均返回 NULL
- cassandra - Cassandra 删除节点并单独使用它
- vue.js - Vue Draggable move方法中的访问属性
- xamarin.forms - 无法完成将 xamarin.froms.android 应用添加到 firebase