检查Shiny服务器中的多个选择

时间:2016-11-21 22:01:31

标签: shiny shiny-server

我正在使用selectInput(....multiple=TRUE)创建用户选择的输入列表,其中用户可以选择多个选项,但我无法检查/读取用户在我的服务器中选择的选项。

如果有人成功试过,请分享一下吗?

例如 - 对于具有以下文件的目录 -

/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)

我的代码在输入框中显示文件名,但我需要执行以下操作

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 

我甚至无法完成第二步工作,任何帮助都能奏效! 谢谢!

1 个答案:

答案 0 :(得分:0)

这是一个关于如何在selectInput中使用多项选择的小例子。您可以通过阅读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()))
                      })