如何解决数据表中闪亮的未对准问题? [英] How to solve shiny mis-alignment issue in datatable?

查看:35
本文介绍了如何解决数据表中闪亮的未对准问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试

  • 使数据表中的所有列具有相同的宽度
  • 将数据表(标头及其内容)向左对齐
  • 达到mainPanel宽度后启用水平滚动

但是我的数据表自动居中于mainPanel,其标题和内容也未对齐.

but my datatable gets automatically centered to the mainPanel, its header and content are also misaligned.

示例:

library(shiny)
library(dplyr)
library(DT)

ui <- fluidPage(

   titlePanel("Test Example"), 

   mainPanel(
     width = 10, 
     dataTableOutput("cars.table")
   )
)

server <- function(input, output) {
   output$cars.table <- renderDataTable({
      t(cars[1:10, ]) %>% 
       datatable(class = "compact small", 
                 options = list(columnDefs = list(list(width = "25px", targets = "_all")), scrollX = TRUE, autoWidth = TRUE, 
                                paging = FALSE, ordering = FALSE, searching = FALSE))
   })
}

shinyApp(ui = ui, server = server)

更新2019/05/03:

Update 2019/05/03:

我相信此问题指出此类问题是由 autoWidth = TRUE 引起,但是问题没有解决方案,如果要调整列宽,也无法删除 autoWidth = TRUE .

I believe this question states that such issue was caused by autoWidth = TRUE, but there is no solution under the question, and if we want to adjust column width, we can't delete autoWidth = TRUE as well.

推荐答案

要进行对齐,可以使用 className = dt-left .

For alignment you can use className = dt-left.

我猜参数'fillContainer = T'可以完成滚动工作.

And I guess the argument `fillContainer = T' does the job for scrolling.

library(shiny)
library(dplyr)
library(DT)

ui <- fluidPage(

  titlePanel("Test Example"), 

  mainPanel(
    width = 10, 
    dataTableOutput("cars.table")
  )
)

server <- function(input, output) {
  output$cars.table <- renderDataTable({
    t(cars[1:10, ]) %>% 
      datatable(class = "compact small", fillContainer = T, 
                options = list(columnDefs = list(list(className = 'dt-left', width = "25px", targets = "_all")), scrollX = TRUE, 
                               paging = FALSE, ordering = FALSE, searching = FALSE))
  })
}

shinyApp(ui = ui, server = server)

这篇关于如何解决数据表中闪亮的未对准问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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