在R Shiny中使用DT :: renderDataTable时,如何隐藏行名? [英] How do I suppress row names when using DT::renderDataTable in R shiny?

查看:117
本文介绍了在R Shiny中使用DT :: renderDataTable时,如何隐藏行名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照2.3 ,则没有行名选项

  output $ subsettingTable<-DT :: renderDataTable(
subsetTable(),filter ='top',server = FALSE ,
选项= list(pageLength = 5,autoWidth = TRUE,行名= FALSE
))

我的问题类似于此处。那里的答案是 renderTable ,我试过使用 DT :: renderDataTable 使答案在那里成功

解决方案

请仔细阅读函数的帮助页面,以了解哪个参数属于哪个函数。在您的情况下, rownames 参数属于 datatable()函数,但是您实际上将其放在了<$里面c $ c> options 参数,那肯定是错误的。 DT :: renderDataTable()接受数据对象或表小部件作为其第一个参数(同样,请阅读其帮助页面),因此以下两个表达式均应起作用:

  DT :: renderDataTable(datatable(
subsetTable(),filter ='top',server = FALSE,
选项= list(pageLength = 5,autoWidth = TRUE),
行名= FALSE
))

DT :: renderDataTable(
subsetTable() ,filter ='top',server = FALSE,
选项= list(pageLength = 5,autoWidth = TRUE),
rownames = FALSE

在后一种情况下, rownames = FALSE 传递给 datatable ()内部,根据帮助页面的 ... 参数的文档。


As per the explanation in section 2.3 here, I can remove rownames for a datatable by setting rownames = FALSE

How do I suppress row names when using DT::renderDataTable in R shiny? The following doesn't work because if you look at the dataTables options reference there is no rownames option

  output$subsettingTable <- DT::renderDataTable(
    subsetTable(), filter = 'top', server = FALSE, 
    options = list(pageLength = 5, autoWidth = TRUE, rownames= FALSE
    ))

My question is similar to the one here. The answers there are for renderTable and I've tried making the answers there work with DT::renderDataTable with zero success.

解决方案

Please be very careful to read the help pages of functions to know which argument belongs to which function. In your case, the rownames argument belongs to the datatable() function, but you actually put it inside the options argument, and that is certainly wrong. DT::renderDataTable() accepts either a data object or a table widget as its first argument (again, please read its help page), so either of the following expressions should work:

DT::renderDataTable(datatable(
    subsetTable(), filter = 'top', server = FALSE, 
    options = list(pageLength = 5, autoWidth = TRUE),
    rownames= FALSE
))

DT::renderDataTable(
    subsetTable(), filter = 'top', server = FALSE, 
    options = list(pageLength = 5, autoWidth = TRUE),
    rownames= FALSE
)

In the latter case, rownames = FALSE is passed to datatable() internally, per documentation of the ... argument of the help page.

这篇关于在R Shiny中使用DT :: renderDataTable时,如何隐藏行名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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