R Shiny Dashboard DataTable Column Width [duplicate]

有些话、适合烂在心里 提交于 2019-12-24 15:04:23

问题


I am building a Shiny dashboard and one panel on the dashboard is a DataTable.

Below is my code:

  output$table = DT::renderDataTable(b1, selection = 'single')

The width of columns in the data table is now adjusted with the width of column name. However, some cell values are text, and those text are squeezed to display in multiple lines as they are longer than the column names.

I am wondering if there is a way to have the column width adjusted to fit the cell values in one line.

Or, is there a way to set a fixed width for the columns and get the full content of cell value by hover over?

Thanks in advance.


回答1:


You can use the ellipsis plugin to limit the number of visible characters of the cells and to have the full content of the cells in a tooltip.

library(DT) 

dat <- data.frame(
  A = c("fnufnufroufrcnoonfrncacfnouafc", "fanunfrpn frnpncfrurnucfrnupfenc"),
  B = c("DZDOPCDNAL DKODKPODPOKKPODZKPO", "AZERTYUIOPQSDFGHJKLMWXCVBN")
)

datatable(
  dat, 
  plugins = "ellipsis",
  options = list(
    # limit cells in columns 1 and 2 to 17 characters
    columnDefs = list(list(
      targets = c(1,2),
      render = JS("$.fn.dataTable.render.ellipsis( 17, false )")
    ))
  )
)



来源:https://stackoverflow.com/questions/55165477/r-shiny-dashboard-datatable-column-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!