Pregunta

Is there a way to do multi-level sorting in a gvisTable in googleVis? I am using Shiny to display a gvisTable like this:

x <- gvisTable(tabData,options=list(sortColumn=2,showRowNumber='TRUE',allowHtml='TRUE'),chartid=tabID)

I am wondering if there is a way to sort the values, say, first by column 2 then by column 3.

If gvisTable does not have this feature but there is another type of table from another package other than googleVis that can do it in Shiny, that would be fine as well. Any ideas?

¿Fue útil?

Solución

install.packages('shiny', type = 'source')

ui.r:

library(shiny)
shinyUI(bootstrapPage(
  dataTableOutput('tbl')
))

server.r:

library(shiny)
shinyServer(function(input, output) {
  output$tbl <- renderDataTable({
    data.frame(x = 1:10, y = c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5))
  })
})

From the dataTables description: http://datatables.net/examples/basic_init/multi_col_sort.html

"This multiple sorting mechanism is always active if the bSort initialiser is true (it is by default) and the end user can activate it by 'shift' clicking on the column they want to add to the sort."

Thus, when you run this application, try sorting by "y" and then shift-clicking x (watch the purple-highlighted arrows in the column heading), to see that the "y" column remains sorted, while the "x" column changes the sort-order leaving y fixed.

Otros consejos

Your could sort the data source, right?

orderedData <- tabData[order(tabData[2], tabData[3]),]
x <- gvisTable(orderedData,options=list(showRowNumber='TRUE',allowHtml='TRUE'),chartid=tabID)

You can simply sort by multi-columns, for example:

sortColumn=c(0,1,2) ## sort by columns 1:3
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top