简体   繁体   English

R Shiny 数据表隐藏“显示条目” label 在表格顶部但不是下拉框

[英]R Shiny data table hide the “Show Entries” label on top of the table but not dropdown box

please I have the following code to display a datatable:请我有以下代码来显示数据表:

fluidRow(column(3,
                dataTableOutput(outputId="table01", width = '100px')))

and this is how the rendered table is created:这就是创建渲染表的方式:

output$table01 <- DT::renderDataTable({  
  df <- get_mp_data()
  if(is.null(df)){
        df <- data.frame()
  }else{
        upcolor = "lightblue"
        downcolor = "lightblue"
        col_name = "CHG"
        df <- datatable(df
                        , rownames = FALSE 
                        , caption = paste0("Pre/Post Duration")
                        , filter = 'none'
                        , options = list(scrollX = F
                                         #, lengthChange = FALSE  # this feature hides the "Show Entries" on top of the table, so we won't be able to customize how many entries we can see all together
                                         , pagingType = "numbers"  # this hides the Next and Previous buttons -->  https://datatables.net/reference/option/pagingType
                                        , autoWidth = T
                                        ,pageLength = 5 # this determines how many rows we want to see per page
                                        , info = FALSE #  this will hide the "Showing 1 of 2..." at the bottom of the table -->  https://stackoverflow.com/questions/51730816/remove-showing-1-to-n-of-n-entries-shiny-dt
                                        ,searching = FALSE  # this removes the search box  ->  https://stackoverflow.com/questions/35624413/remove-search-option-but-leave-search-columns-option
                                        ,columnDefs = list(list(width = '4', targets = c(3) ) 
                                                           ,list(width = '4', targets = c(2) )
                                                           )   # careful, column counting STARTS FROM 0 !
                                        )) %>% 
              formatStyle(col_name,
                          #background = styleColorBar(range(df[, c(col_name)]), 'lightblue'),
                          background = color_from_middle(df[, c(col_name)] , downcolor,   upcolor),
                          backgroundSize = '98% 88%',
                          backgroundRepeat = 'no-repeat',
                          backgroundPosition = 'center')
  }
  return(df)
})

The problem with this code is that it shows "Show Entries" on the top left hand side of the table that takes a lot of useless space.这段代码的问题是它在表格的左上角显示“显示条目”,占用了大量无用的空间。 I would like to only keep the dropdown and hide the text "Show Entries".我只想保留下拉菜单并隐藏文本“显示条目”。 I couldn't find anything here # https://datatables.net/reference/option about this.我在这里找不到任何东西# https://datatables.net/reference/option关于这个。 Notice how I don't want to use "lengthChange = FALSE" since this will also hide the dropdown box that allows to customize how many rows can be displayed all together.请注意我不想使用“lengthChange = FALSE”,因为这也会隐藏允许自定义可以一起显示多少行的下拉框。 Thank you谢谢在此处输入图像描述

You can use this option:您可以使用此选项:

datatable(iris, options = list(
  language = list(lengthMenu = "_MENU_")
))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM