简体   繁体   English

ioslides演示文稿不呈现png图像文件

[英]ioslides presentation doesn't render png image file

Below is a small ioslides presentation with an embedded shiny application in one of the slides. 下面是一张小型ioslides演示文稿,其中一张幻灯片中嵌入了闪亮的应用程序。 Another slide attempts to display a png image file. 另一张幻灯片尝试显示png图像文件。 When I "Run Presentation" in RStudio, the png image doesn't render, and I get a warning: 当我在RStudio中“运行演示文稿”时,png图像无法渲染,并且出现警告:

Warning in file.create(to[okay]) : cannot create file 'C:\\Users\\John\\AppData\\Local\\Temp\\Rtmpkty0sF\\file3b247a612422_files/C:/Develop/data/smile.png', reason 'Invalid argument' file.create(to [okay])中的警告:无法创建文件'C:\\ Users \\ John \\ AppData \\ Local \\ Temp \\ Rtmpkty0sF \\ file3b247a612422_files / C:/Develop/data/smile.png',原因为“无效参数”

If I remove the shiny code, and remove "runtime: shiny" from the YAML, then the png image renders properly, without the warning. 如果我删除了闪亮的代码,并从YAML中删除了“运行时:闪亮”,则png图像将正确呈现,而不会发出警告。 In this case RStudio shows a button to "knit" the presentation, instead of "Run Presentation" for the shiny application. 在这种情况下,RStudio将显示一个用于“编织”演示文稿的按钮,而不是用于闪亮应用程序的“运行演示文稿”。

Similar problems were reported here: 这里报告了类似的问题:

ioslides css and logo ioslides CSS和徽标

and here: 和这里:

Error adding images in ioslides 在ioslides中添加图像时出错

Here is my setup: Windows 9, RStudio version 0.99.473, Package: rmarkdown version: 0.7.3, Package: shiny version: 0.12.2.9001, Package: httpuv version: 1.3.3, 这是我的设置:Windows 9,RStudio版本0.99.473,软件包:rmarkdown版本:0.7.3,软件包:闪亮版本:0.12.2.9001,软件包:httpuv版本:1.3.3,

Here is my RMarkdown code: 这是我的RMarkdown代码:

---
title: "ioslides Presentation with Shiny"
author: "John Doe"
date: "August 27, 2015"
output: 
  ioslides_presentation: 
    widescreen: true
    smaller: true
    transition: 0.1
    self_contained: true
runtime: shiny
---

## Slide with Embedded Inline Shiny Application

Below is an embedded inline shiny application:
```{r, echo=FALSE}
inputPanel(
  selectInput("n_breaks", label = "Number of bins:",
              choices = c(10, 20, 35, 50), selected = 20),

  sliderInput("bw_adjust", label = "Bandwidth adjustment:",
              min = 0.2, max = 2, value = 1, step = 0.2)
)

renderPlot({
  hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input$n_breaks),
       xlab = "Duration (minutes)", main = "Geyser eruption duration")

  dens <- density(faithful$eruptions, adjust = input$bw_adjust)
  lines(dens, col = "blue")
})
```

## Slide With a Smiling Face

![smiling_face](C:/Develop/data/smile.png)

JJ Allaire (CEO of RStudio!) provided answers on GitHub here: RStudio的首席执行官JJ Allaire在GitHub上提供了以下答案:
jjallaire answers jjallaire答案

I will summarize by saying that if an ioslides presentation contains an embedded shiny application, then it requires that image files be either stored in the same directory as the .Rmd file, or in a subdirectory, not in a separate directory branch. 我将总结一下,如果一个ioslides演示文稿包含一个嵌入式的闪亮应用程序,那么它要求图像文件要么存储在与.Rmd文件相同的目录中,要么存储在子目录中,而不是在单独的目录分支中。 The image files should be referenced using relative file paths, instead of absolute paths. 应该使用相对文件路径而不是绝对路径来引用图像文件。 This is because when ioslides presentations are knitted (parsed), they are stored as a directory containing .js and other files, and all images must be copied into that directory. 这是因为编织(解析)ioslide演示文稿时,它们被存储为包含.js和其他文件的目录,并且所有图像都必须复制到该目录中。 Hard-coding absolute file paths prevents RStudio knitr from copying the image files. 硬编码绝对文件路径可防止RStudio Knitr复制图像文件。

I copied the image file to an "image" subdirectory, and changed my rmarkdown code to this, and it now works: 我将映像文件复制到“ image”子目录,并将我的rmarkdown代码更改为此,现在可以正常工作:

![smiling_face](image/smile_small.png)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM