I'd like to use a simple Shiny app to upload some spectroscopic data (in .jdx format) from a specific folder and evaluate them using ChemoSpec of readJDX packages. I have prepared the following code for R Shiny, but I still can't evaluate the data after the selection of the folder containing them.
Code
The code is, as follows:
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 = "samples", 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)
I keep on obtaining the following error
Error: $ operator is invalid for atomic vectors
despite I wrote the following function that works in the R environment, but I can't convert it into the R Shiny one:
a<-getwd()
spec <- files2SpectraObject(
gr.crit = "samples", freq.unit = "ppm", int.unit = "intensity",
descrip = "test import", fileExt = "\\.JDX", path = a
)
dat <- spec$data
I'd be extremely grateful if anybody could attend to this matter!