Question

How to render JPEG stored in S3 bucket in RShiny

I am trying to read in a JPEG hosted on an S3 bucket inside an RShiny app I have developed. So far, the only luck I have had is manually downloading the image and rendering the image using imageOutput()/renderImage(). I would like to do something more programmatic.

I have tried a few things. Firstly:

bucket_name <- "mybucket/images"
object_key <- "myimage.jpeg"
image1 <- aws.s3::s3read_using(FUN = jpeg::readJPEG,
                           native = TRUE,
                           object = object_key,
                           bucket = bucket_name)

This generates a large nativeRaster object which I have displayed in the viewport using grid::grid.raster(image1). However I have not been able to think of a way to actually render this in shiny. While not ideal, I would even be open to saving this image somehow and then rendering the locally saved version.

I have also tried to use the get_object() function from aws.s3 which results in a large raw object: aws.s3::get_object(object_key, bucket_name), but I have been unable to successfully translate this raw object to a rendered image in RShiny.

I appreciate any ideas you may have, thank you!

EDIT with Solution: I went with Mikko's solution and used save_object() to simply save the image into a folder which was read in via renderImage().

 2  37  2
1 Jan 1970

Solution

 0

I went with Mikko's solution and used save_object() to simply save the image into a folder which was read in via renderImage().

2024-07-19
mbriganti