Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjusting the width of the datatable using DT in R

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

like image 307
Ashmin Kaul Avatar asked Oct 12 '17 12:10

Ashmin Kaul


People also ask

How do you set the column width in a data table?

As such, the width of the column can be controlled using the columns. width option. This example shows the first column being set to width: 200px (note that this is not pixel perfect in a table, the browser will make some adjustments!), a width that is reflected in the fixed column.

How do I create a Datatable width?

As such, if you apply the width attribute to the HTML table tag or inline width style ( style="width:100%" ), it will be used as the width for the table (overruling any CSS styles).

How do you set column width in lightning Datatable?

Set to 'fixed' for columns with equal widths. Set to 'auto' for column widths that are based on the width of the column content and the table width. The default is 'fixed'. Array of the columns object that's used to define the data types.


1 Answers

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

like image 163
Pork Chop Avatar answered Oct 18 '22 00:10

Pork Chop