Failing to load an image hosted in rstudio connect

I want to load an image, to my RShiny application. The image is hosted in an api in Rstudio connect. The api was created using plumber.

I used the following code to load the image:

library(httr)
val <- GET(url ="url for the image",
                   add_headers("Authorization" = "Key my-api-key")) 
image<-img(src = paste(val),width="100px",height="100px")

However, when I deploy the RShiny application, the image appear as a broken image. I tried with several other images that available online, and they seem to be working fine.
Any help is appreciated regarding this.

Maybe you need to extract the content and save it to file as you would most likely receive binary data.

if (val$status == 200) {
 f<-tempfile()
  writeBin(httr::content(val), f)
}
image<-img(src = f,width="100px",height="100px")

You might need to save the image elsewhere to meet requirements, or encode it in base64 to inculde it directly in the page. But the gist of it is that you have to use the content, not the return value from httr::GET.

then

1 Like

After encoding to base64 this issue is resolved !
Thank you!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.