Out of memory when displaying image (approx 15 mb)

Hi I have an app that works fine locally, but get disconneted due to "out of memory" in Shinyapps.
The app simply loads an image and display it (tested different libraries, now using plotly)
Problem arise when loading in a larger picture (e.g. 15 mb).
The instance size is set to 1 GB so i dont see that this should be a problem. Also i down-convert the image to max height =250px before displaying on plotly (which is around 2 mb). This is verified using the pryr:object_Size library.

Also tried using Display and plot as alternatives to plotly, but i also here get disconnected (out of memory).
Any ideas highly appreciated!
Thanks

Demo :
https://sundsoy.shinyapps.io/shinyapps_test/

See code below:

library(shinydashboard)
library(shiny)
library(shinycssloaders)
library(shinyWidgets)   
library(dashboardthemes) 
library(plotly)
library(BiocManager)
options(repos = BiocManager::repositories())
library(EBImage)    # Read Image (png + jpeg)
library(pryr)


#                                  UI   
#################################################################################
options(shiny.maxRequestSize = 30*1024^2) # max 30 mb file size 
options(expressions = 500000)

sidebar <- dashboardSidebar(
  sidebarMenu(
    fileInput(   "file1", "Choose image File", accept = c(".jpg",".png") ),
    menuItem(    "test", tabName = "dashboard", icon = icon("dashboard")) 
  )
)



body <- dashboardBody(
  shinyDashboardThemes( theme = "grey_dark" ),
  tabItems(
    tabItem(tabName = "dashboard",
 fluidRow(  
              plotlyOutput("org_image")
        )   
      )   
  )
 )
 

ui <-  dashboardPage(
  dashboardHeader(title = "test"),
  sidebar,
  body
)



 
#                                  SERVER   
#################################################################################
server <- function(input, output, session) {
 
#--------------------------------------------------------------------------------
#                                Org image 
#--------------------------------------------------------------------------------
 output$org_image <- plotly::renderPlotly({     
      plot_ly(type="image",z=img()*255) 
 })   
 
#--------------------------------------------------------------------------------
#                                  Read image  
#--------------------------------------------------------------------------------
  img <- reactive({
    inFile<-input$file1 
    if (is.null(inFile$datapath)){     } 
    else {   
      file <- inFile$datapath 
      img <-   EBImage::readImage(file )  %>% EBImage::resize(h=250) %>% EBImage::rotate(270 )
      print(pryr::object_size(img))
      img
    }
  })
   
}

shinyApp(ui, server)
 


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.