How to freeze header and left columns of a table output

2,223 views
Skip to first unread message

Nestor Montaño

unread,
Sep 18, 2013, 2:24:22 PM9/18/13
to shiny-...@googlegroups.com
When we show a table report in a spreadsheet we usually freeze the header (1 or more rows) and some (1 or more again) left columns, is there a way to do this in a output table in shiny?

Kirill Savin

unread,
Sep 18, 2013, 4:11:59 PM9/18/13
to shiny-...@googlegroups.com
Possible with some dancing with CSS styles. You can override default bootstrap styles with yours by adding tags$style(type = 'text/css', 'insert your tags here') to ui.r or by creating a separate css file and linking it with tags$link(rel="stylesheet", type="text/css", href=*yourfile.css in www folder")

You may want to check for CSS styles here and here.

I may put up an example on weekend if you kindly remind me.

Nestor Montaño

unread,
Sep 18, 2013, 5:45:47 PM9/18/13
to shiny-...@googlegroups.com
Thanks, 
I have no experience with css so I'll read about it and give it a try.
Message has been deleted

Monika Cichocka

unread,
Feb 11, 2014, 5:21:55 AM2/11/14
to shiny-...@googlegroups.com
Hi Nestor. Did you find the solution? I've got the same problem and I am also not familiar with CSS styles.


Stéphane Laurent

unread,
Feb 11, 2014, 5:58:17 AM2/11/14
to shiny-...@googlegroups.com

Monika Cichocka

unread,
Feb 11, 2014, 7:07:35 AM2/11/14
to shiny-...@googlegroups.com
Thanks Stéphane. I get the idea but have problems with implementing it in R.
So far I made this:

tags$style(type="text/css", '#my_Table  td:first-child {position: fixed;
  top: auto;
  }

The problem is that I want the first column to have fixed position when I scroll horizontally but to move when I scroll vertically (like in Excel with freeze panes command).
I like the idea in the link you provided (http://jsfiddle.net/emn13/YMvk9/) but I can't implement it in R.
Do you have any idea how to do this?


Stéphane Laurent

unread,
Feb 11, 2014, 7:34:02 AM2/11/14
to shiny-...@googlegroups.com
I am novice in html, I don't know. If nobody provides a solution then I will try myself in the future.

I would firstly try that, but this is rather a random attempt :

tags$script(type="text/css", 
   "#my_Table  td {
            margin:0;
            border:3px solid grey; 
            border-top-width:0px; 
            white-space:nowrap;
        }
        div { 
            width: 600px; 
            overflow-x:scroll;  
            margin-left:5em; 
            overflow-y:visible;
            padding-bottom:1px;
        }
        .headcol {
            position:absolute; 
            width:5em; 
            left:0;
            top:auto;
            border-right: 0px none black; 
            border-top-width:3px; /*only relevant for first row*/
            margin-top:-3px; /*compensate for top border*/
        }
        .headcol:before {content: 'Row ';}
        .long { background:yellow; letter-spacing:1em; }"
  }

Monika Cichocka

unread,
Feb 11, 2014, 8:19:10 AM2/11/14
to shiny-...@googlegroups.com
It didn't work even when I renamed e.g. ".headcol" to "td:first-child" because this is my "headcol". I got stuck here:
   tags$style(type="text/css", '#my_Table th:first-child{
            position:absolute;
            width:5em;
            left:auto;
            top:auto;
            padding-bottom:1px;
        }'),

    tags$style(type="text/css", '#my_Table td:first-child{
            position:absolute;
            width:5em;
            left:auto;
            top:auto;
            padding-bottom:1px;
        }'),
    tags$style(type="text/css",'#my_Table {
      width: 600px;
      overflow-x:scroll; 
      margin-left:5em;
      overflow-y:visible;
     
    }')
Now I scroll horizontally all the table so it gives me strange effect- the first column has fixed position so when scrolling it overlaps other columns. I don't know how to exclude first column from scrolling so that scrolling panel start after first column like here http://jsfiddle.net/emn13/YMvk9/.

Dmitri

unread,
Feb 12, 2014, 6:14:49 AM2/12/14
to shiny-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages