我想保存被选为数组或其他可索引对象的行。但是,我似乎没有得到如何做到这一点。
这是代码。给我带来麻烦的一行是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)
答案 0 :(得分:2)
input$tableId_rows_selected
返回所选表格行的索引。
在您的情况下,您应该将peakTable
分组以获取所选行的数据。
你可以尝试:
output$rowData <- renderText({peakTable[s,]})
input$table1
不会保留您在output$table1