How to select a specific folder and then evaluate multiple files in Shiny (spectroscopic files involving ChemoSpec packages)

I'd like to use a convert my code into a simple Shiny app, aimed to upload some spectroscopic data (in .jdx format) from a specific folder and, then, evaluatin them using ChemoSpec of readJDX packages.
I prepared the following R code that correctly works in the R environment:

library(ChemoSpec)
a<-getwd()
spec <- files2SpectraObject(
  gr.crit = "samples", freq.unit = "ppm", int.unit = "intensity",
  descrip = "test import", fileExt = "\\.JDX", path = a
)
dat <- spec$data

However, when I try to convert it in the R Shiny environment, I keep on obtaining errors. I prepared the following code:

library(shiny)
library(shinyFiles)
library(ChemoSpec)
library(DT)

ui <- fluidPage(
    
    shinyDirButton('folder', 'Folder select', 'Please select a folder', FALSE),
    textOutput("dir"),
    dataTableOutput("rendered_file")
)

server <- function(input,output,session){
    
    observe({  
        if(!is.null(input$folder)){
            shinyDirChoose(input, 'folder', roots=getVolumes())
            output$dir <- renderText(as.character(input$folder))
            }
    })
    
    dir <- reactive({
        input$folder
    })

    goButton <- eventReactive(input$folder,{
        spec <- files2SpectraObject(
            gr.crit = "campione", freq.unit = "ppm", int.unit = "intensity",
            descrip = "test import", fileExt = "\\.JDX", path = input$folder)
        spec$data
    })

    output$rendered_file <- DT::renderDataTable({
     req(input$folder)
     goButton()
     })
}
shinyApp(ui = ui, server = server)

but I keep on obtaining the following error:

Error in : operator is invalid for atomic vectors

I'd be extremely grateful if anybody could help me with this matter!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.