我正在尝试在for循环中向ocr_data()
添加进度条,但是当串联使用时,该过程非常缓慢。
我正在尝试利用并行以加快从ocr_data(x)
生成表的过程。
代码粘贴在这里:
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)`
我遇到了错误
“任务1失败-“会话”不是ShinySession对象。”
我不确定如何解决此错误,请帮忙。