'Next' action button won't click through images stored on local folder

32 views Asked by At

I am new to shiny and trying to make an app which allows users to view images one by one. I have thousands of JPGs in a folder and I want to be able to display an image and allow a user to click a button and the next image in that folder will be displayed (And the old one deleted) So far I can load up the first image, but when I click next I get an error message "invalid filename argument".

Is anyone able to advise where I'm going wrong please?

My code is as follows:

dir <- "local.dir/www"
img_files <- list.files(dir, full.names = TRUE)

ui <- pageWithSidebar(
  headerPanel("Data"),
  sidebarPanel(actionButton("goButton", "Next")),
    plotOutput("plot", height=500)
)
server <- function(input, output,session) {
  
    values <- reactiveValues()
  values$count <- 1
  
   plot <- eventReactive(input$goButton,{
    
    
    if(values$count != length(img_files)){
      values$count <- values$count + 1
      return(img_files[values$count])
    }
    else{
         return(img_files[length(img_files)])
    }
  })
  
  output$plot <- renderImage({
        if(input$goButton == 0){
      return(list(src = img_files[1]))
    }
    img()
  }, deleteFile = TRUE)  
  
}


shinyApp(ui = ui, server = server)
0

There are 0 answers