Displaying jpeg/(magick?) images on shiny

shiny

#1

Hello! Working on my wedding app still :smiley: (Problem with encoding when publishing to shinyapps.io)

Now I am trying to use magick package to mix a picture me with a picture of the fiance to create an artsy mix. I try to follow advice found on here and wrap the image to a list: https://shiny.rstudio.com/articles/images.html

However, I don’t get it to show on UI, instead get the error: “cannot coerce type ‘externalptr’ to vector of type ‘character’”. I don’t really know where to start debugging it. The error message obviously points to data type problems, does it try to coerce object “img” containing the picture to char datatype in that list?

This is essentially the script which does the mixing and tries to return the resulting pic to UI. (hisPic and herPic are created outside, containing a number of images in a list)

output$picture <- renderImage({

hisPic <- round(runif(1,1,length(hisPics)),0)
herPic <- round(runif(1,1,length(herPics)),0)

img <- c(hisPics[[hisPic]],herPics[[herPic]])

if(input$kuvatyyli==1){

img <- image_flatten(img,"Modulate")


}else if(input$kuvatyyli==2){
  
img <- image_flatten(img,"Add")
}else if(input$kuvatyyli==3){
img <- image_mosaic(img,"Add")
  
}else{
  img <- image_mosaic(img, "Modulate")
}

img <- image_rotate(img, input$kulma)

picture <- list(src = img,
     width = 400,
     height = 300)

picture

})

UI has imageOutput(“picture”) accordinly

Any help is much appreciated! :slight_smile:


#2

No one has tried to show images (rather than plots) on their Shiny apps?


#3

Actually finally stumbled upon a solution. The problem was in the magick-image object type. Instead, I saved the file to www-folder and sourced that to renderImage.