从DataTable Shiny中检索行

时间:2016-01-15 08:14:05

标签: r shiny

我想保存被选为数组或其他可索引对象的行。但是,我似乎没有得到如何做到这一点。

这是代码。给我带来麻烦的一行是output$rowData <- renderText({input$table1[s]})

fluidPage(

   title = " Nanoproject",

   h1("Peak Table and Views"),

   # first row will contain the peak table and peak view 
   fluidRow(
   # give the table half of the page
      column(6, dataTableOutput('table1'), height = 2500),

   #give the other half of the page to the images
      column(6 , 
       imageOutput("image1",width = "auto",height = "auto"),
       htmlOutput("rowData")
   )

server.R

# prompt user to select the peak table file
writeLines("Please select the peaks file")
peaksPath = file.choose()

# read the tsv file 
peaksTable = read.csv(peaksPath , header = TRUE , row.names = NULL , sep = "\t")

server = function(input, output) {
    output$table1 = renderDataTable({
    # the peak table 
    datatable(peaksTable,
          # when rowname is false each row does not have a numeric # associated with it 
          rownames = TRUE,
          # specify the name of the column headers
          colnames = c("Seqnames", "Start", "End","Width","Strand","P","Q","Effectsize",
                       "FDR","Keep","Gene_name","Gene.nearest","Count","Count.pred",
                       "Coverage","Local.mut.density","Base.context.GC","Tn.Context.TpC",
                       "Tn.context.CpG","Dnase","Activechrom","Hetchrom","Rept"),
          # make the table scrollable (horizontally)
          options = list(scrollX = TRUE))

},
escape = FALSE)

output$image1 <- renderImage({

# save which row was selected
s = input$table1_rows_selected

# output the data of the row that was selected
output$rowData <- renderText({input$table1[s]})

#output$rowsSelected <- renderText({s})
list(src=paste0(imagePath,"/peak" , s,".png"),width=700,height=2500)},deleteFile=FALSE)

1 个答案:

答案 0 :(得分:2)

input$tableId_rows_selected返回所选表格行的索引。

在您的情况下,您应该将peakTable分组以获取所选行的数据。

你可以尝试:

output$rowData <- renderText({peakTable[s,]})

input$table1不会保留您在output$table1

中显示的表格