0

I am creating a input list for user selection using selectInput(....multiple=TRUE), where user can select multiple options, but I am unable to check/read what options user selects in my server.R.

If anyone has successfully tried it can you please share?

For example - For a directory which has folowing file -

/User/DE/AvsB.de.txt- 

Feature.ID  Read.Count.All  Read.Count.A    Read.Count.B FC
ENSG00000121898 3367.375403 6734.750807 0   0
ENSG00000104435 2161.235573 4322.471145 0   0
ENSG00000229847 2111.660196 4223.320392 0   0
ENSG00000046889 1302.993351 2605.986702 0   0

/User/DE/CvsD.de.txt -

Feature.ID  Read.Count.All  Read.Count.C    Read.Count.D    FC
ENSG00000248329 373.0309339 746.0618679 0   0
ENSG00000144115 352.3786793 704.7573586 0   0
ENSG00000158528 351.6252529 703.2505057 0   0
ENSG00000189058 350.5375828 701.0751656 0   0


library(gtools)
D_files <- list.files(path = "/User/DE/",pattern = "*.de.txt" ,recursive = F, full.names = T)
D_filename <- vector()
for(i in 1:length(D_files)){
  D_filename[i] <- D_files[i]
}
D_filename <- unlist(strapplyc(D_filename, "/User/DE/(.*).de.txt"))
names(D_files)<- D_filename


  ui <- fluidPage(

    mainPanel(

      uiOutput("Quad_plot_comparison"),
      HTML("<br><br>"), 
      br()
  )
  )

  server <- function(input, output) {
    output$Quad_plot_comparison <- renderUI({
      selectInput(inputId = "vars",label = h3("Select comparison"), choices = mixedsort(D_files), multiple = T)
    })
  }

  shinyApp(ui, server)

My code shows the file names in the input box, but I need to do following

1- Select multiple file names from the box
2- Read user input ( variables in the input box) 
3- Read the files corresponding to these user input into a data frame 

I am not even able to get the second step to work, any help will work! Thanks!

AnkP
  • 631
  • 2
  • 9
  • 18
  • It's definitely possible, please post a reproducible example – HubertL Nov 21 '16 at 23:07
  • Hi @HubertL, thanks! I just posted my code – AnkP Nov 21 '16 at 23:18
  • reproducible means I don't need your files to reproduce : Please build a small dataset so I can reproduce your problem easily (I just want to copy-paste-run in R to see) – HubertL Nov 22 '16 at 01:34
  • also where is your code for reading the file and why don't you put the `selectInput` directly in the ui function? – HubertL Nov 22 '16 at 01:36
  • @HubertL -I added the sample files in the question. Also, I need to provide hard coded path to the directory containing the files. and yes I had selectInput directly in ui but I was trying to fix the code and trying options! – AnkP Nov 22 '16 at 03:19

1 Answers1

0

This is a small example on how to use multiple selection in selectInput. You can adapt it to you scenario by reading the file in the reactive:

library(shiny)
shinyApp(ui=fluidPage(selectInput("select", "choose", c(1,2,3), multiple = TRUE), 
                      textOutput("selected", inline=TRUE)), 
         server=function(input, output){
                      selected <- reactive(ifelse(is.null(input$select), "nothing", 
                                                  paste(input$select, collapse=",")))
                      output$selected <- renderText(paste("Selected=",selected()))
                      })
HubertL
  • 19,246
  • 3
  • 32
  • 51