Adjusting the width of the datatable using DT in R

Ashmin Kaul picture Ashmin Kaul · Oct 12, 2017 · Viewed 7.1k times · Source

This is a script for a data table that is created in R shiny.I am trying to fit the plot within the box completely by adjusting the width of the plot. Below is the script of the plot along with the box in which I am trying to fit. Please help me to adjust the width of the plot produced using datatable. Also, I don't want to increase the width of the box. A link to apossible solution would be of great help. Thanks.

Script for datatable:

r3_blood = subset(patient, handling == "Blood test" & employee == "r3")
  datatable(r3_blood, options = list(
    searching = FALSE,
    pageLength = 5,
    lengthMenu = c(5, 10, 15, 20)
  ))

Script to fit table in box:

box( title = "Case Summary", status = "primary", height = 
  "575",solidHeader = T, 
                          dataTableOutput("sankey_table"))

DataTable

Answer

Pork Chop picture Pork Chop · Oct 12, 2017

1) Along with already proposed possible duplicate ticket where you can use div(DT::dataTableOutput("table"), style = "font-size: 75%; width: 75%")

2) Also you can add scrollX = T into your options

library(DT)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(),
  dashboardBody(
    box(title = "Case Summary", width = 4,status = "primary", height = "575",solidHeader = T, dataTableOutput("Table"))
  )
)

server <- function(input, output, session) {

  output$Table <- renderDataTable(
    datatable(mtcars, options = list(searching = FALSE,pageLength = 5,lengthMenu = c(5, 10, 15, 20), scrollX = T))
  )
}
shinyApp(ui, server)

enter image description here