如何将数据表列宽调整得更长

问题描述 投票:0回答:1

在 shiny 我有一个数据表输出,在第一页上,数据表和第二页是不同的,因为下面的第一张照片是数据表的第一页,第二张照片是数据表的第二页。您可以看到第二页具有正确的行高和宽度。如何使数据表中的每个页面都相同

我还在数据表中设置了行高,还有一个问题是如何调整列收入的宽度只会变得更长,并让其他列具有我尝试使用的默认设置的宽度

options = list(
            columnDefs = list(
              list(
                targets = c(2, 4), 
                className = "dt-center",
                width = "80px",
              ),

但这并没有改变什么

这是我的完整代码

datatable(df1() %>%  mutate(`URL SO` = ifelse(!is.na(`URL SO`), sprintf('<a href="%s">Click Here</a>', `URL SO`), NA)) %>% filter(Brand %in% input$brand, Service %in% input$service, Month %in% input$month),escape = F,
                selection = "none",
                extensions = "AutoFill",
                callback = JS(callback), 
                options = list(
                  autoFill = TRUE,
                  pageLength = 10,
                  lengthMenu = c(10, 20, 50, 100),
                  scrollX = TRUE
                )) %>% 
formatCurrency("Revenue",currency = "Rp. ",digits = 2L,mark = ",") %>% 
formatStyle( 0, target= 'row',lineHeight='90%') %>% 
        formatStyle(
          "Due Date", backgroundSize = '98% 88%',
          backgroundColor = styleInterval(brks, clrs),
          backgroundRepeat = 'no-repeat',
          backgroundPosition = 'center'
        ) 
r shiny datatables shinydashboard dt
1个回答
0
投票

尝试使用选项

autoWidth = TRUE
和CSS
table {table-layout: fixed;}

library(DT)
library(shiny)

ui <- fluidPage(
  tags$head(
    tags$style(
      HTML("table {table-layout: fixed;}")
    )
  ),
  DTOutput("dtable")
)

server <- function(input, output, session) {
  output[["dtable"]] <- renderDT({
    datatable(
      mtcars,
      options = list(
        autoWidth = TRUE,
        columnDefs = list(
          list(targets = 0:3, width = "200px") 
        )
      )
    )
  })
}

shinyApp(ui, server)
© www.soinside.com 2019 - 2024. All rights reserved.