googleVis: multi-level sorting feature gvisTable sortColumn?

梦想的初衷 提交于 2019-12-07 07:46:16

问题


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?


回答1:


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.




回答2:


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)



回答3:


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

sortColumn=c(0,1,2) ## sort by columns 1:3


来源:https://stackoverflow.com/questions/19791917/googlevis-multi-level-sorting-feature-gvistable-sortcolumn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!