How do I suppress row names when using DT::renderDataTable in R shiny?

六月ゝ 毕业季﹏ 提交于 2019-11-27 17:06:32

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/31486738/how-do-i-suppress-row-names-when-using-dtrenderdatatable-in-r-shiny

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