1

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!

  • Author of `ChemoSpec` and `readJDX` here. `spec$data` is going to be a matrix of spectra in rows. I don't know `shiny` well enough to say how a matrix would be handled by your code. Might be simpler to make a prototype that just uses `readJDX` to read in a single spectrum, and get that working optimally. Then, if your intent is to display multiple spectra, use a loop and `readJDX` to get them all read in and displayed however you wish. 1/2 – Bryan Hanson Mar 11 '20 at 01:49
  • 2/2 Your code right now would put the spectra in an enormous table, not graphical -- is that what you intend? Also, looks like some functions in `DT` and `shiny` mask each other so be careful to always load them in the same order. – Bryan Hanson Mar 11 '20 at 01:51
  • Dear @BryanHanson, thank you very much for your useful advice! I'd try to follow your indications and update the code asap in the loop form. I f you are interested, I'll update you about it – Eugenio Alladio Mar 11 '20 at 08:34
  • I'd love to see the results! When you get a simple version working post it here as an edit to the original question, and point out why you were seeing the error so future readers can use the post. When you get a fancier version working, please put it on one of the public servers and link to it here. Also, for testing purposes you might switch to an IR spectrum as it will load faster than NMR -- you can find these online. – Bryan Hanson Mar 11 '20 at 15:00

0 Answers0