Search code examples
listuniqueshiny

Shiny: Creating an unique list from input file


I have been trying for days to create a list from my uploaded file, using Shiny. My file (.csv) is uploaded and shows a table corresponding to the csv-file. However, I have a column named 'Peptide.Sequence', and from that I want to create a list of unique names, as it contains several duplicates (from there I want to be able to give each peptide a user specific value, and so forth, but that's another task).

I've been trying many different approaches, and searched the web (incl stack overflow) for answers. At this point I'm hoping for some pointers on how to move on...

I keep getting the error:

ERROR: 'arg' must be NULL or a character vector

Thanks beforehand.

**ui.r**
library(shiny)

shinyUI(fluidPage(

  titlePanel("File Input"),
   sidebarLayout(
    sidebarPanel(
      fileInput("file", "Upload the file"), 

      checkboxInput(inputId = 'header', 
                    label = 'Header', 
                    value = TRUE),

      radioButtons(inputId = 'sep', 
                   label = 'Separator', 
                   choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), 
                   selected = ',')),


      uiOutput("pep"),



    mainPanel(
      uiOutput("tb")
    )

)))

**Server.r**
library(shiny)

shinyServer(function(input, output) {




  lc.ms <- reactive({
    file1 <- input$file

    if(is.null(file1)){return()} 

    read.table(file=file1$datapath, 
               sep=input$sep, 
               header = input$header)

  })


  output$filedf <- renderTable({

    if(is.null(lc.ms())){return ()}

    input$file
  })


  output$table <- renderTable({

    if(is.null(lc.ms())){return ()}

    lc.ms()

    })


  peptides <- as.list(unique(lc.ms$Peptide.Sequence))

  output$pep <- renderUI({

    selectInput(
      inputId = 'peptides',
      label = 'peptides',
      multiple = TRUE)

  })

outputOptions(output, 'pep', suspendWhenHidden=FALSE)

  output$tb <- renderUI({

    if(is.null(lc.ms()))
      h4("Waiting for file :)")

    else
      tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("lc.ms", tableOutput("table")))
  })

Solution

  • You have a sintax error in your radio button (an extra )) and you have to give a mainPanel argument. Here your ui.r

    shinyUI(fluidPage(
    
      titlePanel("File Input"),
       sidebarLayout(
    mainPanel(),
        sidebarPanel(
          fileInput("file", "Upload the file"), 
    
          checkboxInput(inputId = 'header', 
                        label = 'Header', 
                        value = TRUE),
    
          radioButtons(inputId = 'sep', 
                       label = 'Separator', 
                       choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), 
                       selected = ','),
    
    
          uiOutput("pep"),
    
    
    
        mainPanel(
          uiOutput("tb")
        )
    
            ))
    
    ))