knitr::opts_chunk$set(echo = F) library(shiny) library(DT) library(mzrtsim) data("hmdbcms") data("monams1") data("monahrms1")
inputPanel( sliderInput( "n", "Numbers of the compounds", min = 10, max = 500, step = 1, value = 100 ), sliderInput( "inscutoff", "intensity cutoff for MS1 spectra", min = 0, max = 0.5, step = 0.01, value = 0.05 ), sliderInput( "ppm", "mass to charge ratio shift in ppm", min = 0, max = 50, value = 5 ), sliderInput( "sampleppm", "m/z shift in ppm within one sample", min = 0, max = 50, value = 5 ), sliderInput( "mzrange", "mass to charge ratio range", min = 50, max = 1500, value = c(100,1000) ), sliderInput( "rtrange", "retention time range", min = 0, max = 1000, value = c(0,600) ), sliderInput( "scanrate", "scan rate per secound", min = 0, max = 1, value = 0.2 ), textInput("pwidth", "peak width for all peaks", value = "10"), textInput("pheight", "peak height for all peaks", value = "12,9,16,13,10,9,5,11,7,11,13,9,7,18,11,12,9,15,10,13,16,13,10,9,5,11,7,11,13,9,9,15,10,13,16,13,10,9,5,11,13,9,7,18,11,12,9,15,10,13,12,9,16,13,10,9,5,11,7,11,13,9,7,18,11,12,9,15,10,13,16,13,10,9,5,11,7,11,13,9,9,15,10,13,16,13,10,9,5,11,13,9,7,18,11,12,9,15,10,13"), sliderInput( "baseline", "noise baseline", min = 50, max = 1000, value = 100 ), sliderInput( "baselinesd", "standard deviation for noise", min = 0, max = 100, value = 30 ), textInput("rf", "response factor of all compounds", value = "100"), sliderInput( "tailingfactor", "tailing factor for peaks", min = 0.5, max = 2, value = 1.2 ), textInput("name", "Enter File Name:", value = "test"), numericInput("seed", "Enter Seed:", value = 1), radioButtons(inputId = 'db', label='database', choices = c('HMDB','MoNA','MoNAhr'), selected = 'MoNAhr'), checkboxInput('unique','Unique compound name',value = TRUE) ) sim <- reactive({ if(input$db == 'HMDB'){ data("hmdbcms") simmzml( name=input$name, db=hmdbcms, n = input$n, inscutoff = input$inscutoff, mzrange = input$mzrange, rtrange = input$rtrange, ppm = input$ppm, sampleppm = input$sampleppm, scanrate = input$scanrate, pwidth = as.numeric(input$pwidth), pheight = as.numeric(trimws(unlist(strsplit(input$pheight, ",")))), baseline = input$baseline, baselinesd = input$baselinesd, rf = as.numeric(input$rf), tailingfactor = input$tailingfactor, seed=input$seed, unique=input$unique ) file1 <- paste0(input$name,'.mzML') file2 <- paste0(input$name,'.csv') return(list(file1 = file1, file2 = file2)) } else if(input$db == 'MoNA'){ data("monams1") simmzml( name=input$name, db=monams1, n = input$n, inscutoff = input$inscutoff, mzrange = input$mzrange, rtrange = input$rtrange, ppm = input$ppm, sampleppm = input$sampleppm, scanrate = input$scanrate, pwidth = as.numeric(input$pwidth), pheight = as.numeric(trimws(unlist(strsplit(input$pheight, ",")))), baseline = input$baseline, baselinesd = input$baselinesd, rf = as.numeric(input$rf), tailingfactor = input$tailingfactor, seed=input$seed, unique=input$unique ) file1 <- paste0(input$name,'.mzML') file2 <- paste0(input$name,'.csv') return(list(file1 = file1, file2 = file2)) }else{ data("monahrms1") simmzml( name=input$name, db=monahrms1, n = input$n, inscutoff = input$inscutoff, mzrange = input$mzrange, rtrange = input$rtrange, ppm = input$ppm, sampleppm = input$sampleppm, scanrate = input$scanrate, pwidth = as.numeric(input$pwidth), pheight = as.numeric(trimws(unlist(strsplit(input$pheight, ",")))), baseline = input$baseline, baselinesd = input$baselinesd, rf = as.numeric(input$rf), tailingfactor = input$tailingfactor, seed=input$seed, unique=input$unique ) file1 <- paste0(input$name,'.mzML') file2 <- paste0(input$name,'.csv') return(list(file1 = file1, file2 = file2)) } })
shiny::renderPlot({ sim <- suppressWarnings(sim()) x <- mzmlviz(sim$file1) })
DT::renderDataTable({ sim <- suppressWarnings(sim()) read.csv(sim$file2) })
downloadHandler( filename = paste0(input$name,'.mzML'), content = function(file) { files <- sim() file.copy(files$file1, file) } )
downloadHandler( filename = paste0(input$name,'.csv'), content = function(file) { files <- sim() file.copy(files$file2, file) } )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.