1

I'm trying to fix the width of very wide table in shiny but haven't mange to do it. I try the answer here Shrink DT::dataTableOutput Size but it didn't work, I also tried the answer from here https://github.com/rstudio/DT/issues/29 with percentage and pixels for all the columns and it didn't work neither. This is an example of the table and problem I have:

shinyApp(
    ui = fluidPage(
      DT::dataTableOutput("table")
    ),
    server <- function(input, output) {
      x <- cbind(iris,iris,iris,iris)
      output$table <- DT::renderDataTable(x)
    }
  )
Alejandro Andrade
  • 2,196
  • 21
  • 40

1 Answers1

1

I think this does what you want:

library(shiny)
shinyApp(
  ui = fluidPage(
    DT::dataTableOutput("table",width='500px')
  ),
  server <- function(input, output) {
    x <- cbind(iris,iris,iris,iris)
    output$table <- DT::renderDataTable(x,options=list(scrollX=T))
  }
)
Florian
  • 24,425
  • 4
  • 49
  • 80
  • almost but not, because I don't want to scroll I want to visualize the whole data at once, it doesn't matter that the font is small. I know its possible with `div(table, style = "font-size:50%")` but that doesn't work in my real table because i have image in the table so font gets small but the tables doesn't. I need something the just shrinks the table. – Alejandro Andrade Jan 23 '18 at 16:17