2016-01-15 7 views
1

Я хотел бы сохранить строку, выбранную как массив или какой-либо другой индексный объект. Но я просто не понимаю, как это сделать.Извлечение строк из DataTable 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

Прочтите страницу справки. Обычно «cat» используется для его побочного эффекта и возвращает NULL. –

ответ

1

input$tableId_rows_selected возвращает индексы строк таблицы, которые выбраны.

В вашем случае вы должны подмножить peakTable, чтобы получить данные из выбранных строк.

Вы можете попробовать:

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

input$table1 не имеет таблицу, отображение в output$table1

+0

Я пробовал это, но, я получаю сообщение об ошибке ** Ошибка в '. .data.frame' (peaksTable, s): не определены выбранные столбцы ** – Crt

+0

Забыл запятую после s, работает ли она сейчас? – NicE

+0

Я получаю еще одну ошибку ** аргумент 1 (тип «список») не может обрабатываться «cat» ** – Crt

Смежные вопросы