renderImage working in local but not in shinyapps.io

1,296 views
Skip to first unread message

Shami Gupta

unread,
Aug 13, 2015, 11:45:18 AM8/13/15
to Shiny - Web Framework for R
I am trying to display different jpg image based upon a prediction result using shiny.. Have saved the images are pre-rendered in directory 'www'...

Now while using renderImage, it doesnt pickup directly from www and I have to provide exact path (relative)

server.R

 output$preImage
<- renderImage({
    testdata
= iris[0,]
    testdata
= subset(testdata, select=-Species)
    testdata
[1,"Sepal.Length"]= input$sl
    testdata
[1,"Sepal.Width"]= input$sw
    testdata
[1,"Petal.Length"]= input$pl
    testdata
[1,"Petal.Width"]= input$pw
    op
=predict(modFit,newdata=testdata)
    filename
<- normalizePath(file.path('./www/',paste(as.character(op),'.jpg', sep='')))
    list
(src = filename, alt = paste("Iris type ", paste(as.character(op))))
 
}, deleteFile = FALSE)

ui
.R

    imageOutput
("preImage")

This works fine in the local version - but when I move to the server using deployApp(), the image is not showing in the server - just alternate text is shown

What changes are needed in Code / configuration / deployment ?




Winston Chang

unread,
Aug 13, 2015, 1:50:37 PM8/13/15
to Shami Gupta, Shiny - Web Framework for R
I think that the directory is probably not writable on shinyapps.io. Can you try writing to a file in /tmp, using the tempfile() function? You would something like this:
  filename <- tempfile(fileext = ".png")

-Winston


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/36ae3ba5-0170-46fb-9c4c-d21c4321829c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ian Bangor

unread,
Dec 1, 2015, 4:47:01 PM12/1/15
to Shiny - Web Framework for R
I am having a similar problem. Have you found a solution?  Thanks

Ian

Ian Bangor

unread,
Dec 1, 2015, 5:19:48 PM12/1/15
to Shiny - Web Framework for R, shami...@gmail.com
Can you explain more please.  Thank you

zhanyang zhang

unread,
Jan 12, 2016, 8:22:15 PM1/12/16
to Shiny - Web Framework for R
I'm having the same problem. any suggestions?

Huidong TIAN

unread,
Jan 13, 2016, 7:45:37 AM1/13/16
to Shiny - Web Framework for R
Could you post the address of your app? There must be some debug information needed for solving the problem.

Kallie Horiuchi

unread,
Feb 11, 2016, 12:47:42 PM2/11/16
to Shiny - Web Framework for R
I am having a similar issue.  The image is reactive and works fine locally with this: 

Original Code (with images in main /app folder):
output$img <- renderImage({
      pic <- switch(input$member,
                "Person1" = "per1.png",
                "Person2" = "per2.png",
                "Person3" = "per3.png",
                "Person4" = "per4.png",
                "Person5" = "per5.png")
      list(src=pic,height=150)
      },deleteFile=FALSE)


Looking at Winston's code, I attempted to fix with this:

Adjusted code that still doesn't run (with images in main /app folder):
output$img <- renderImage({
      pic <- tempfile(switch(input$member,
                "Person1" = "per1.png",
                "Person2" = "per2.png",
                "Person3" = "per3.png",
                "Person4" = "per4.png",
                "Person5" = "per5.png"))
      list(src=pic,height=150)
      },deleteFile=FALSE)

The app deploys to shinyapps.io fine and all text (code not included) runs fine, just no picture shows up.  What else do I need to do to correct this?

Tony Liu

unread,
Jun 1, 2016, 3:32:48 AM6/1/16
to Shiny - Web Framework for R
I am having the same problem. Image can be shown when run locally, it is saved in the www/ file and uploaded, but not shown in shinyapps.io
Reply all
Reply to author
Forward
0 new messages