r - 将图像上传到 R 闪亮可下载到 pdf
问题描述
我正在尝试将图像上传到 R Shiny 并将图像下载到报告 app.r 但是当我编织报告时,它给了我图像数据而不是图像
关于我在这里做错了什么的任何想法?一如既往地提前谢谢你
library(shiny)
ui <- fluidPage(
titlePanel('Upload Image Test'),
sidebarLayout(
sidebarPanel(
fileInput(
inputId = "file1",
label = "Upload Image",
accept = c('image/png', 'image/jpeg','image/jpg')
),
tags$hr()),
mainPanel(
textOutput("filename"),
imageOutput(outputId = "uploaded_image"),
downloadButton("report", "Generate report")
)
)
)
server <- function(input, output) {
re1 <- reactive({gsub("\\\\", "/", input$file1$datapath)})
output$uploaded_image <- renderImage({list(src = re1())})
output$report <- downloadHandler(
filename = "report.pdf",
content = function(file) {
tempReport <- file.path(tempdir(), "report.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
params <- list(n = input$slider, image = input$file1)
rmarkdown::render(tempReport, output_file = file,
params = params,
envir = new.env(parent = globalenv())
)
}
)
}
shinyApp(ui, server)
报告.Rmd
---
title: "report"
author: "Author"
date: "4/14/2019"
output: pdf_document
params:
image: "Null"
n: "Null"
---
```{r}
params$image
params$n
解决方案
问题是 RenderImage 将在使用后删除文件,除非 deleteFile = False。这是要更改的行,删除此行:
re1 <- reactive({gsub("\\\\", "/", input$file1$datapath)})
添加这个:
output$uploaded_image <- renderImage({list(src = input$file1$datapath)}, deleteFile = FALSE)
推荐阅读
- javascript - 无法将 PDF 返回的响应转换为 JavaScript 中的 base64
- java - 使用 Rest Assured 从 JSON API 获取唯一属性
- java - 函数是追加而不是递增,有问题
- c# - 从字符串列表中获取枚举值
- geospatial - GeoMesa\GeoSpark - 多边形中不同时间点的点
- spring-boot - @Query 注释不适用于自定义弹性搜索查询
- php - Iphone Mail 无法正确显示来自 PHP 的消息
- android - 反应原生。原生 Android 组件未呈现
- python - 如何将抓取的 Json 数据保存到 CSV 或文本文件
- c# - 将类对象转换为接口 C#