R闪亮仪表板数据表列宽 [英] R Shiny Dashboard DataTable Column Width

查看:83
本文介绍了R闪亮仪表板数据表列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Shiny仪表板,并且该仪表板上的一个面板是DataTable。

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

下面是我的代码:

  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?

谢谢。

推荐答案

您可以使用省略号插件可限制单元格的可见字符数量,并在工具提示中包含单元格的全部内容。

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

这篇关于R闪亮仪表板数据表列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆