LaTeX PDF与ShinyApp中来自网络的图像 [英] LaTeX PDF with images from web in shinyapp

查看:119
本文介绍了LaTeX PDF与ShinyApp中来自网络的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经能够将URL中的图像包含在执行![](url.com)的闪亮应用程序生成的PDF报告中.稍后,一些markdown版本出现以下错误:! Unable to load picture or PDF file https://i0.wp.com/wptavern.com/wp-content/uploads/2016/07/stack-overflow.png?ssl=1表示相同的代码. pandoc_args: ["--extract-media", "."]添加到YAML下载中本地镜像文件,但仅在本地r-markdown文件中起作用.

I used to be able to include images from URLs in PDF reports generated from shiny apps doing ![](url.com). A few markdown versions later I get the following error: ! Unable to load picture or PDF file https://i0.wp.com/wptavern.com/wp-content/uploads/2016/07/stack-overflow.png?ssl=1 for the same code. Adding pandoc_args: ["--extract-media", "."] to the YAML downloads the imaged file locally but only works in local r-markdown files.

  • shinyapp如何存储本地文件以及如何使extract-media解决方法起作用?
  • 如何在Shinyapps中将网络图像包含在PDF中?
  • How does shinyapp store local files and how to get the extract-media workaround to function?
  • How to include web images in PDF's in shinyapps?
title: "Test"
header-includes:
    - \usepackage{graphicx}
    - \usepackage{hyperref}
output:
  pdf_document:
    latex_engine: xelatex
    pandoc_args: ["--extract-media","."]
    number_sections: yes
    keep_tex: yes
classoption: article
papersize: A4
fontsize: 10pt
geometry: margin=0.9in
linestretch: 1.15
---
## R Markdown
![click](https://i0.wp.com/wptavern.com/wp-content/uploads/2016/07/stack-overflow.png?ssl=1)

server.R块触发报告生成

## img report
output$downloadImgReport <- downloadHandler(
    filename = function() {
        paste0(format(Sys.time(), '%Y%m%d'),'-WS-CM-image-report-',docounts()$count, '.pdf')
    },
    content = function(file) {
        src <- normalizePath('Untitled.Rmd')
        src1 <- normalizePath('logo.png')
        owd <- setwd(tempdir())
        on.exit(setwd(owd))
        file.copy(src, 'Untitled.Rmd', overwrite = TRUE)
        file.copy(src1,'logo.png')
        library(rmarkdown)
        out <- render('Untitled.Rmd', output_format=pdf_document(latex_engine = "xelatex"))
        writetolog(1,session$token)
        file.rename(out, file)
    }
)

推荐答案

最新版本的rmarkdown要求图像必须在本地下载.将pandoc_args: ["--extract-media","."]添加到YAML标头可用于本地rmarkdown文件,但不适用于闪亮的应用程序环境.

The latest version of rmarkdown requires images to be downloaded locally. Adding pandoc_args: ["--extract-media","."] to the YAML header works for local rmarkdown files but not in a shiny app environment.

将rmarkdown降级到1.9版以下将使图像可以自动下载.

Downgrading rmarkdown below version 1.9 will enable images to be automatically downloaded.

或者,可以使用download.file()在本地下载文件,并使用绝对路径进行引用.

Alternatively, files can be downloaded locally using download.file() and reference with an absolute path.

title: "Test"
header-includes:
    - \usepackage{graphicx}
    - \usepackage{hyperref}
output:
  pdf_document:
    latex_engine: xelatex
    pandoc_args: ["--extract-media","."]
    number_sections: yes
    keep_tex: yes
classoption: article
papersize: A4
fontsize: 10pt
geometry: margin=0.9in
linestretch: 1.15
---
## R Markdown
download.file(url = "https://i0.wp.com/wptavern.com/wp-content/uploads/2016/07/stack-overflow.png?ssl=1"), destfile = "stack-overflow.png")
![click]("stack-overflow.png")

这篇关于LaTeX PDF与ShinyApp中来自网络的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆