PikaPika
PikaPika

Reputation: 1

How to make the column text appear to single line instead of multiple lines in datatable of shiny R

This is how my day column in the datatable appears:

enter image description here

I removed some of the columns to adjust the day column to make it to appear in single row instead of two rows. The date-column is now like this: '2022-' and in next line '11-24'. I want date column to be like this '2022-11-24'. How can I do this without using width parameter.

I tried all datatable parameters, but nothing seems to work.

Upvotes: 0

Views: 594

Answers (1)

Stéphane Laurent
Stéphane Laurent

Reputation: 84529

Use the CSS white-space: nowrap:

library(DT)
library(shiny)

dat <- mtcars
dat$test <- "2022-12-08"

ui <- fluidPage(
  tags$head(
    tags$style(HTML(
      "
      td {
        white-space: nowrap;
      }
      "
    ))
  ),
  DTOutput("dtable")
)

server <- function(input, output, session) {
  output$dtable <- renderDT({
    datatable(dat)
  })
}

shinyApp(ui, server)

Upvotes: 1

Related Questions