0

In shiny I have a datatable output that on the first page, the data table and the second page are different, as the first photo below is the first page of the datatable, and the second photo is the second page of the datatable. You can see that the second page has the right line height and width. How do you make every page in the datatable the same

enter image description here

enter image description here

I have also set the line height in the datatable and one more quetion how do I adjust the width for column revenue only become longer and let the other columns have the width with the default settings i tried using

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

but it didn't change anything

here's my full code

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'
        ) 

Updated :

enter image description here

enter image description here

1 Answers1

0

Try using the option autoWidth = TRUE and the 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)
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225