问题
Not certain why this simple code is not working. The goal is to upload an image from a device and view as shiny output. I keep getting an error, *****Error: invalid filename argument*****
library(jpeg)
library(shiny)
library(magick)
library(magrittr)
ui <- fluidPage(
#-------------------------------------Header Panel--------------------------------------------------#
titlePanel('Invoice Recognition & Interpretation -IRI'),
#--------------------------------Sidebar : Image Upload---------------------------------------------#
sidebarLayout(
sidebarPanel(
fileInput(inputId = "file1",
label = "Upload Invoice",
accept = c('image/png', 'image/jpeg','image/jpg')
),
tags$hr()
),
mainPanel(
imageOutput(outputId = "Invoice")
)
)
)
server <- function(input, output) {
re1<-reactive({ input$file1})
output$Invoice<-renderImage({re1()})
}
shinyApp(ui, server)
回答1:
You are most of the way there, however, you need to understand that your fileInput returns a data frame and not just the path. Also, the renderImage is similar to an <img> and you need to assign the src.
library(shiny)
ui <- fluidPage(
titlePanel('Invoice Recognition & Interpretation -IRI'),
sidebarLayout(
sidebarPanel(
fileInput(
inputId = "file1",
label = "Upload Invoice",
accept = c('image/png', 'image/jpeg','image/jpg')
),
tags$hr()
),
mainPanel(
textOutput("filename"),
imageOutput(outputId = "Invoice")
)
)
)
server <- function(input, output) {
re1 <- reactive({gsub("\\\\", "/", input$file1$datapath)})
output$Invoice <- renderImage({list(src = re1())})
}
shinyApp(ui, server)
来源:https://stackoverflow.com/questions/47683197/shiny-image-upload