datatables - adding tabletools

2,031 views
Skip to first unread message

Haider Ali

unread,
Nov 26, 2013, 8:54:15 PM11/26/13
to shiny-...@googlegroups.com
Hi - Is there a easy way to add TableTools in the shiny datatables impl i.e. http://datatables.net/extras/tabletools/

Thanks

Yihui Xie

unread,
Nov 27, 2013, 1:31:16 AM11/27/13
to Haider Ali, shiny-...@googlegroups.com
It is not shipped with Shiny, but I guess you probably can just
install it in your app, and pass the required initialization
parameters to the data table:

renderDataTable({
# a data frame here
}, options = list(
"sDom" = 'T<"clear">lfrtip',
"oTableTools" = list(
"sSwfPath" = "www/swf/copy_csv_xls_pdf.swf"
))
)
# suppose you put the swf file under www/swf/

See http://datatables.net/release-datatables/extras/TableTools/swf_path.html

I did not test it, so please play with it and let me know if there are
any problems. Thanks!

Regards,
Yihui
--
Yihui Xie <yi...@rstudio.com>
Web: http://yihui.name

Alain Vanlanduyt

unread,
Dec 31, 2013, 5:43:22 AM12/31/13
to shiny-...@googlegroups.com
Hi Yihui and thanks for your code
 
I have a similar problem and I try this but without any change on my table in Shiny
 
in server.R :
 
output$RRTable = renderDataTable({
dataT #My data frame
 },options = list(aLengthMenu = c(10, 30, 50), iDisplayLength = 10,"sDom" = 'T<"clear">lfrtip',  "oTableTools" = list("sRowSelect" = "single", "sSwfPath" = "www/swf/copy_csv_xls_pdf.swf" )))
 
 
What do you mean with "install it in your app" ? must something else be installed.
 
Thanks
 
Regards
 
Alain

Yihui Xie

unread,
Jan 8, 2014, 2:27:19 AM1/8/14
to Alain Vanlanduyt, shiny-discuss
Yes, I mean the .swf file, which is not shipped with shiny, and you
have to download it separately: http://datatables.net/download/

After you unzip TableTools-x.x.x.zip, you put the three folders js/,
css/, and swf/ under the www/ directory of your app. Here is a minimal
example:

# ui.R

shinyUI(basicPage(
tags$head(
tags$link(href='css/TableTools.css', rel="stylesheet", type="text/css"),
tags$script(src='js/ZeroClipboard.js'),
tags$script(src='js/TableTools.js')
),
dataTableOutput('foo')
))

# server.R

shinyServer(function(input, output) {
output$foo = renderDataTable(
iris,
options = list(
"sDom" = 'T<"clear">lfrtip',
"oTableTools" = list(
"sSwfPath" = "swf/copy_csv_xls_pdf.swf"
))
)
})


Regards,
Yihui

Alain Vanlanduyt

unread,
Jan 9, 2014, 5:25:26 AM1/9/14
to shiny-...@googlegroups.com, Alain Vanlanduyt
Yihui
 
Thank you so much
 
I receive a warnig message about a compatibility problem between Datatable (version 1.9.4 is required) and  TableTools version 2; i add this in ui.R and it works :
 
tags$script(src='js/jquery.dataTables.js')
 
Alain

Joseph Lee

unread,
Jan 25, 2014, 1:44:47 AM1/25/14
to shiny-...@googlegroups.com, Alain Vanlanduyt
Everything in this thread works for me and I've got tabletools working.  However, when I disable vertical scrolling with "bPaginate" = FALSE, the table get stuck on "Processing..."  I'm trying to load all of the data into the table at once because otherwise export to CSV will only export the visible data (data on the visible page), not the entire table.  If I use infinite scrolling, then it will export the entire table, but only if I've scrolled down to the bottom to load all of the data.

A lot of people using datatables run into this same export CSV/visible data problem when the data is handled server side.  I would have though shiny was running datatables on the client side.  Disabling server side with "bServerSide" = FALSE didn't do anything.  Any ideas how shiny is sending the data?

Thanks,
Joe

Joseph Lee

unread,
Jan 26, 2014, 8:52:05 PM1/26/14
to shiny-...@googlegroups.com, Alain Vanlanduyt
I was able to solve my issue with     
iDisplayLength = 500000,
sScrollY = "300px",
bPaginate = FALSE,
bScrollCollapse = TRUE,

Interestingly, iDisplayLength = -1 didn't work, so I had to use a really large number.

Also, clientside datatables search should be case-insensitive.  However, my search is case sensitive.  Setting bCaseInsensitive TRUE didn't fix the issue, so is datatables being run serverside on shiny?

Patrick Toche

unread,
Jan 27, 2014, 2:09:56 AM1/27/14
to shiny-...@googlegroups.com, Alain Vanlanduyt
# ui.R

shinyUI(basicPage(
  tags$head(
    tags$link(href='css/TableTools.css', rel="stylesheet", type="text/css"),
    tags$script(src='js/ZeroClipboard.js'),
    tags$script(src='js/TableTools.js')
  ),
  dataTableOutput('foo')
))

# server.R

shinyServer(function(input, output) {
  output$foo = renderDataTable(
    iris,
    options = list(
      "sDom" = 'T<"clear">lfrtip',
      "oTableTools" = list(
        "sSwfPath" = "swf/copy_csv_xls_pdf.swf"
      ))
  )
})


 
For me, this line 

"oTableTools" = list("sSwfPath" = "swf/copy_csv_xls_pdf.swf")

does nothing: I don't get the Copy/CSV/Excel/PDF/Print buttons.

In www/swf, I have

copy_csv_xls_pdf.swf
copy_csv_xls.swf

I also tried "sSwfPath" = "www/swf/copy_csv_xls_pdf.swf"

I also get the warning "Warning: TableTools 2 requires DataTables 1.9.0 or newer - www.datatables.net/download"

Joseph Lee

unread,
Jan 27, 2014, 11:34:53 PM1/27/14
to shiny-...@googlegroups.com
You have to do the extra step that Alain mentioned - download the latest version of datatables, copy jquery.dataTables.js into the www directory, and then add it to ui.R.

Owe Jessen

unread,
Jan 28, 2014, 3:35:24 AM1/28/14
to shiny-...@googlegroups.com
Is there any way to specify the locale of the export - the problem is that I get csv's with "." as decimal, and my German version of Excel will not read it correctly.

On Wednesday, November 27, 2013 2:54:15 AM UTC+1, Haider Ali wrote:

con...@patricktoche.com

unread,
Jan 28, 2014, 9:40:05 AM1/28/14
to shiny-...@googlegroups.com
Thanks Joseph!

You have to do the extra step that Alain mentioned - download the latest version of datatables, copy jquery.dataTables.js into the www directory, and then add it to ui.R.

I have jquery.dataTables.js  , TableTools.js  , ZeroClipboard.js  in www/js  and TableTools.css in www/css

do I need more than that?  Any problem with the code below?

# ui.R 

shinyUI(basicPage( 
  tags$head( 
    tags$link(href='css/TableTools.css', rel="stylesheet", type="text/css")
    , tags$script(src='js/ZeroClipboard.js')
    , tags$script(src='js/TableTools.js')
    , tags$script(src='js/jquery.dataTables.js')
  ), 
  dataTableOutput('foo') 
)) 
# server.R 

shinyServer(
  function(input, output) { 
    output$foo = renderDataTable( 
      iris
      , options = list( 
        "sDom" = 'T<"clear">lfrtip'
        , "oTableTools" = list("sSwfPath" = "/swf/copy_csv_xls_pdf.swf")
      ) 
    ) 
  }
)


Yihui has "swf/copy_csv_xls_pdf.swf"

http://datatables.net/extras/tabletools/ has "/swf/copy_csv_xls_pdf.swf" with an extra / before swf

Either way, I don't get the csv/xls/pdf buttons.


I'm using another account because all of a sudden I can't post from my usual account: I get this:

You have limited access to public groups inside your domain. Contact your domain administrator for more information. 

Junjie Zeng

unread,
Feb 16, 2014, 9:52:32 PM2/16/14
to shiny-...@googlegroups.com
Yes, I also have the same files in www/js, www/css, www/swf.
But  I don't get the csv/xls/pdf buttons.
I understand that we by copy these files into www/ directory, we update the Tabletools' file..
Do we need to update the dataTable. Because it is still showing the version is 1.9 and TableTools 2.0....
And I thought it is already dataTable 1.9.4 and TableTools 2.2..... 

Yihui Xie

unread,
Feb 19, 2014, 1:43:15 AM2/19/14
to Joseph Lee, shiny-discuss, Alain Vanlanduyt
At the moment, setting iDisplayLength to nrow(data) is the only
solution if you want to display the whole data. I have written down
other problems that you mentioned, and will try to solve them in the
future (https://github.com/rstudio/shiny/issues/400). Thanks for the
report!

Regards,
Yihui
> --
> You received this message because you are subscribed to the Google Groups
> "Shiny - Web Framework for R" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to shiny-discus...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Yihui Xie

unread,
Feb 19, 2014, 1:46:53 AM2/19/14
to Alain Vanlanduyt, shiny-discuss
Hmm... That is interesting. Shiny already uses DataTables 1.9.4.

Regards,
Yihui

John Luis

unread,
Feb 19, 2014, 7:16:44 AM2/19/14
to shiny-...@googlegroups.com, patric...@free.fr
I don't have the code with me right now, but I was having the same issue.  The way I got it to work was using the addResourcePath() shiny function to specify the location of the swf files.  The js and css files were loading just fine ... but for some reason the swf file was not.  After I added addResourcePath(), it worked beautifully.  Those buttons are totally worth it, so don't give up!  

It was something along the lines of addResourcePath("alias","path/to/swf/directory") in my UI.  Then when calling the swf file, I did "sSwfPath" = "alias/file.swf".

I hope that works for you!

John

Patrick Toche

unread,
Feb 20, 2014, 6:47:58 AM2/20/14
to shiny-...@googlegroups.com, patric...@free.fr
@ John Luis,

Please do post a MWE, because I can't get it to work with your hints. In particular, did you specify an absolute path for the directory, as in "C:\shiny\swf" or is it relative? Did you get it to work on a server?

Using your code, with "path/to/swf/directory" replaced by "swf" or "/swf" or "www/swf" or variations thereof (my swf file is inside a subdirectory of "www" named "swf"), I get:

Error in normalizePath(directoryPath, mustWork = TRUE) : 
  path[1]="swf": No such file or directory

Thanks

Patrick.

John Luis

unread,
Feb 25, 2014, 9:07:13 PM2/25/14
to shiny-...@googlegroups.com, patric...@free.fr
in server.R, here are the options on my renderDataTable()

options=list(
          "sDom" = 'lfT<"clear">rtip',
          "oTableTools"=list(aButtons = c("copy", "csv"), "sSwfPath" = "/tabletools/tt_copy_csv_xls_pdf.swf"))
    
in ui.R, here is where how I set the resource path:
addResourcePath('tabletools','./tt_files')

Adding the resource to ./tt_files directory, with alias "tabletools" is what allows me to reference it as /tabletools/filename.swf in server.R.  It seems trivial and I didn't think this would work, but after hours trying to figure this out, this is what finally did it for me.

I hope that helps!

Albert Vilella

unread,
Jul 1, 2014, 2:54:09 PM7/1/14
to shiny-...@googlegroups.com, patric...@free.fr
I am also trying to get extensions loaded but no luck so far. Has there been any updates on this?

I got a shiny server updated last week, but I still don't see dataTables extensions showing up:

Patrick Toche

unread,
Jul 1, 2014, 3:06:48 PM7/1/14
to shiny-...@googlegroups.com, patric...@free.fr
I personally gave up and moved on ...

Crt Ahlin

unread,
Jul 13, 2015, 5:02:54 AM7/13/15
to shiny-...@googlegroups.com, patric...@free.fr
Just to update this thread, as it seem to be obsolete and to avoid anyone going through the instruction for naught.

DataTables & TableTools support (for new versions of shiny) is described here:
Reply all
Reply to author
Forward
0 new messages