闪亮的应用程序路径错误

时间:2017-12-07 16:54:39

标签: r web-applications shiny ocr

我正在尝试创建一个闪亮的应用程序,上传图像,然后进行OCR。上传部分似乎有效但OCR出错 &#34;错误:路径必须是网址,文件名或原始向量&#34; 感谢任何帮助。< / p>

另一个但相关的说明,是否有人熟悉R中MSER算法的实现?我知道我可以通过R来调用python实现。

library(shiny)
library(magick)
library(magrittr)

ui <- shinyUI(fluidPage(
 titlePanel('Test Code'),
 sidebarLayout(
sidebarPanel(
  fileInput(inputId = 'files', 
            label = 'Select an Invoice',
            multiple = FALSE,
            accept=c('image/png', 'image/jpeg')),
  imageOutput('images')
),
mainPanel(

textOutput('extracted')

)
)
))

server <- shinyServer(function(input, output) {
output$files <- renderTable(input$files)

files <- reactive({
files <- input$files
files$datapath <- gsub("\\\\", "/", files$datapath)
files
})


output$extracted<-renderText({
text <- image_read(list(src = files()$datapath[1])) %>%
  image_resize("2000") %>%
  image_convert(colorspace = 'gray') %>%
  image_trim() %>%
  image_ocr()
  cat(text)


})

output$images <- renderImage({
        list(src = files()$datapath[1],
             height = 800,
             width  = 600,
             alt = "Upload an Invoice in an image format")
      }, deleteFile = FALSE)

}
)


 shinyApp(ui=ui,server=server)

1 个答案:

答案 0 :(得分:0)

您需要按如下方式修复output$extracted

  output$extracted <- renderText({
    if (is.null(input$files)) return(NULL)
    # Fix file path
    text <- image_read(files()$datapath[1]) %>%
      image_resize("2000") %>%
      image_convert(colorspace = 'gray') %>%
      image_trim() %>%
      image_ocr()
    # Print to the console
    cat(text)
    # Return value to be rendered in Shiny
    text
  })