Hi there, I'm new to shiny and I'm working on an app to calculate crop growth from an image. I'm trying to use the fileInput input type to select a file to read but I'm getting an error that says "Warning: Error in path.expand: invalid 'path' argument". I've been unable to find a solution, any ideas?
library(DT)
library(shiny)
library(jpeg)
library(tidyverse)
library(magick)
library(raster)
library(grid)
library(imager)
library(fields)
library(RColorBrewer)
library(shinyFiles)
# Define UI for app--
ui <- fluidPage(
# App title ----
titlePanel("NDVI Calculator App"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
fileInput(inputId = "choose_files",
label = "Input files",
accept = c('image/png', 'image/jpeg','image/jpg'))
)
,
# Main panel for displaying outputs ----
mainPanel(
plotOutput(outputId = "plot")
)
)
)
server <- function(input, output) {
output$plot <- renderPlot({
req(input$choose_files)
#input the image
inp <- input$choose_files
# read and strore the image
img <- readJPEG(inp)
# Separate the color layers into their own data
imgr <- img[,,1]
imgg <- img[,,2]
imgb <- img[,,3]
# Get the VARI calculated from the equation below
vari <- (imgg - imgr)/(imgg + imgr - imgb)
# convert to a cimg
cimg1 <- as.cimg(vari)
# create our gradient from low red to high green
cscale <- scales::gradient_n_pal(c("green", "red"),c(0, 1))
# plot it
plot(cimg1, colourscale=cscale, rescale=FALSE)
})
}
shinyApp(ui= ui, server = server)