Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide certain columns in a responsive data table using DT package

Tags:

I am trying to create a responsive data table for my shiny application using DT package. I want to hide certain columns in advance. For example:

library("shiny") library("DT") shinyApp(   ui = fluidPage(DT::dataTableOutput('tbl')),   server = function(input, output) {     output$tbl = DT::renderDataTable(       iris,extensions="Responsive"     )   } ) 

This output gives me 5 columns. It only hides columns when I narrow the page. But, I want to hide last 3 columns in advance and I just want to see first two columns every time. Is there a way to do that?

Update:

Example output

enter image description here

like image 708
skorkmaz Avatar asked Sep 05 '15 03:09

skorkmaz


People also ask

How to hide columns in dataTables?

To hide multiple columns, columns(). visible() can be used: var dt = $('#example'). DataTable(); //hide the second and third columns dt.

How to hide DataTable column dynamically?

To hide and show columns use columns() and visible() method. Call it on dataTables instance and pass column index in columns() method and false to visible() method. Similarly, pass true to visible() if you want to show the columns.

How do I hide columns in R?

The cols_hide() function allows us to hide one or more columns from appearing in the final output table.


1 Answers

You can hide columns in your table using DT options or extensions.

If you want them to be hidden in advance but have a button to make them visible again, the ColVis extension should work well for you: link

If you just want thme stay hidden, add the following option (can't remember where I've seen its documentation right now..)

options=list(columnDefs = list(list(visible=FALSE, targets=columns2hide))) 
like image 102
user5029763 Avatar answered Oct 12 '22 23:10

user5029763