闪亮的应用程序路径错误
Shiny app path error
我正在尝试创建一个闪亮的应用程序来上传图像,然后进行 OCR。上传部分似乎有效,但 OCR 给出错误 "Error: path must be URL, filename or raw vector" 任何帮助表示赞赏。
另一个相关的注意事项,有人熟悉 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)
您需要按如下方式修复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
})
我正在尝试创建一个闪亮的应用程序来上传图像,然后进行 OCR。上传部分似乎有效,但 OCR 给出错误 "Error: path must be URL, filename or raw vector" 任何帮助表示赞赏。
另一个相关的注意事项,有人熟悉 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)
您需要按如下方式修复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
})