algoquant
algoquant

Reputation: 1107

ioslides presentation doesn't render png image file

Below is a small ioslides presentation with an embedded shiny application in one of the slides. Another slide attempts to display a png image file. When I "Run Presentation" in RStudio, the png image doesn't render, and I get a warning:

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'

If I remove the shiny code, and remove "runtime: shiny" from the YAML, then the png image renders properly, without the warning. In this case RStudio shows a button to "knit" the presentation, instead of "Run Presentation" for the shiny application.

Similar problems were reported here:

ioslides css and logo

and here:

Error adding images in 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,

Here is my RMarkdown code:

---
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)

Upvotes: 0

Views: 2388

Answers (1)

algoquant
algoquant

Reputation: 1107

JJ Allaire (CEO of RStudio!) provided answers on GitHub here:
jjallaire answers

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. 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. Hard-coding absolute file paths prevents RStudio knitr from copying the image files.

I copied the image file to an "image" subdirectory, and changed my rmarkdown code to this, and it now works:

![smiling_face](image/smile_small.png)

Upvotes: 2

Related Questions