2

I am trying to add a progress bar to my ocr_data() in a for loop, but when used in series, the process is terribly slow.
I am trying to utilize parallel in order to speed up the process of generating my table from ocr_data(x).

Code is pasted here:

ui <- fluidPage(

   # Application title
   titlePanel("Test"),

   sidebarLayout(
      sidebarPanel(
        fileInput("ocr_pdf","Upload", accept = '.pdf')),
      mainPanel(
         tableOutput("ocr_plot")))
      )

server <- function(input, output) {

  output$ocr_plot <- renderTable({

  image <- input$ocr_pdf$datapath

  image2 <- pdf_convert(image, dpi = 600)

  image2 <- image_read(image2)


  x <- image2  %>%
    image_resize("2000x") 
  #  image_convert(type = 'Grayscale') %>%
   # image_trim(fuzz = 40) 
  #  image_write(format = 'png', density = '300x300') %>%

cl <- detectCores() - 4
registerDoParallel(cl)

    withProgress(message = 'Calculation in progress',
                 detail = 'This may take a while...', value = 0, {
                   foreach(i = 1:nrow(ocr_data(x)), .combine = cbind, .packages = 'shiny') %dopar% {
                     incProgress(1/nrow(ocr_data(x)))
                     Sys.sleep(0.25)
                   }
                 })


  ocr_data(x)

  stopCluster(cl)
   })
}

# Run the application 
shinyApp(ui = ui, server = server)`

I am running into the error,

"task 1 failed - "'session' is not a ShinySession object."

I am not sure how to fix this error, please help.

Rurouni
  • 963
  • 10
  • 31
Quinn
  • 21
  • 2

0 Answers0