Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
616 views
in Technique[技术] by (71.8m points)

r - Hide certain columns in a responsive data table using DT package

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...