4

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?

719016
  • 9,922
  • 20
  • 85
  • 158

3 Answers3

3
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.

Rguy
  • 1,622
  • 1
  • 15
  • 20
  • 1
    I am half-way through doing this via rCharts, but I bumped into a problem. Waiting to see the resolution: http://stackoverflow.com/q/20971453/719016 – 719016 Jan 07 '14 at 12:19
  • 1
    That's really unfortunate, I found the file in the rCharts package at /inst/apps/notebook/www/assets/ace-shiny.css which uses the url http://fonts.googleapis.com/css?family=Open+Sans+Condensed:700. This is a really ugly solution, but you might just change that to https and compile from source... I imagine more errors will appear after that though. Someone better at server management than I might have a better answer. Alternatively, can you access your server at the http version of the url? – Rguy Jan 07 '14 at 18:36
  • It seems like this is not going to be solved until rCharts cleans up a little bit. I'll chase after that. – 719016 Jan 08 '14 at 10:54
  • I also tried to do it straight on using dataTableOutput without the rCharts wrapping, but my shiny server 0.4.0 complains that `could not find function "dataTableOutput"`, which makes me think it's too old a version of shiny for it. When was dataTable added to shiny? – 719016 Jan 08 '14 at 11:04
  • 1
    You'd be safer using the newest version of shiny, which I believe is 0.8.0. The package is under rapid development. – Rguy Jan 08 '14 at 18:39
  • thanks. Updating our shiny server is in the list of things to do, but I don't manage it myself, so at the moment we are stuck with the old version. – 719016 Jan 08 '14 at 18:55
1

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)
Alexis
  • 784
  • 8
  • 32
0

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

sortColumn=c(0,1,2) ## sort by columns 1:3
agstudy
  • 119,832
  • 17
  • 199
  • 261