在R DT数据表的lengthMenu(页面长度菜单)中设置值的名称 [英] Set names of values in lengthMenu (Page Length Menu) in R DT datatable

查看:265
本文介绍了在R DT数据表的lengthMenu(页面长度菜单)中设置值的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R DT软件包制作数据表。我希望用户能够决定/控制是否查看数据中的24、48、72、96或所有行。

I am making a datatable using the R DT package. I would like for the user to be able to decide/control whether to see 24, 48, 72, 96 or all rows in the data.

可以通过以下操作轻松完成:

This can be easily done by setting:

lengthMenu = c(24,48, 72, 96, -1),

在选项列表中,其中-1代表所有条目。

in the option list, where -1 stands for all entries.

问题是用户可能不知道-1代表什么,因此我想使它显示为菜单中可见的字符串 All。用户。

Problem is that the user might not know what -1 stands for, and I would therefore like to make it appear as the string "All" in the menu visible to the user.

通过查看 lengthMenu的文档,我看到可以通过编写

By looking at the documentation for lengthMenu, I see that this could be done by writing

$('#example').dataTable( {
"lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ]
} );

但是我不知道如何将其翻译为R语言。
我尝试使用命名列表,向量和数组,但均未解决。

But I have no idea how to translate that to R-language. I have tried using named list, vectors and arrays but neither worked out.

下面是一个简单的示例:

Below is a simple example:

library(shiny)
library(DT)

ui <- fluidPage(
  DT::dataTableOutput("table")
)

server <- function(input, output) {
  output$table <- DT::renderDataTable({
    DT::datatable(iris, options = list(pageLength = 24, 
                  lengthMenu = c(24,48, 72, 96, -1), paging = T))
  })
}

shinyApp(ui, server) 

任何帮助将不胜感激!

谢谢

推荐答案

应该这样做。有关更多信息,请访问 shiny-examples / 018-datatable-options /

This should do. For more info please visit shiny-examples/018-datatable-options/

library(shiny)
library(DT)

ui <- fluidPage(
  DT::dataTableOutput("table")
)

server <- function(input, output) {
  output$table <- DT::renderDataTable({
    DT::datatable(iris, options = list(pageLength = 24, 
                        lengthMenu = list(c(24,48, 72, 96, -1), 
                                          c('24', '48', '72','96', 'All')),
                         paging = T))
  })
}

shinyApp(ui, server) 

这篇关于在R DT数据表的lengthMenu(页面长度菜单)中设置值的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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