theforestecologist
theforestecologist

Reputation: 4917

PNG file fails to work when I deploy interactive knitr/markdown doc to shinyApps.io

I still can't get my interactive doc to incorporate a png file on shinyApps.io.

Scenario:

  1. I have 2 files on my local machine: .Rmd file + .PNG file
  2. The rmd file consists of the following code:

    ---
    title: "TroubleShoot"
    output:  html_document
    runtime: shiny
    ---
    
    ```{r ,echo=FALSE,eval=T}
    library(png)
    library(grid)
    img <- readPNG("./mypic.PNG")
    grid.raster(img)
    ``` 
    

    As you can see, I've tried using relative paths (i.e., "./") to make this code work. (I've also tried just using the image's name by itself).

  3. However, the document fails to execute properly locally on my machine.

    • It generates the error: Error: unable to open ./mypic.PNG

    • Note: however, it does work if I explicitly define the absolute file path.

  4. I try to publish the interactive doc to shinyApps.io anyway.

    • I use the publish button in RStudio's app window
    • I check the both boxes so that both the .Rmd and .PNG file are uploaded.
  5. I still get the same error once the app is deployed: Error: unable to open ./mypic.PNG

What am I doing wrong?? What can I do to make this work???

Upvotes: 1

Views: 217

Answers (1)

Andrea Barghetti
Andrea Barghetti

Reputation: 126

It works when using the right absolute path for shinyapps.io

it looks like this:

"/srv/connect/apps/APP_NAME/MyImage.png"

I used knitr::include_graphics("/srv/connect/apps/APP_NAME/MyImage.png")

I know it´s a post from 4 years ago, but I had the same question and could not find a good answer anywhere.

Upvotes: 1

Related Questions