Shrink Dt::Datatableoutput Size

Shrink DT::dataTableOutput Size

Try adding width: 75% to your style parameter of the div:

div(DT::dataTableOutput("table"), style = "font-size: 75%; width: 75%")

Shrink DT::dataTableOutput Size

Try adding width: 75% to your style parameter of the div:

div(DT::dataTableOutput("table"), style = "font-size: 75%; width: 75%")

Controlling table width in Shiny dataTableOutput

dataTableOutput does not have an argument width. You can use column within a fluidRow with argument width, supplying an integer between 1 and 12.

library(shinythemes)
ui <- fluidPage(theme = shinytheme("Spacelab"),
fluidRow(
column(
dataTableOutput(outputId = "table"), width = 6)
)
)

server <- function(input, output){
df <- as.data.frame(matrix(0, ncol = 20, nrow = 5))
output$table <- renderDataTable({df},
options = list(scrollX = TRUE))
}
shinyApp(ui = ui,server = server)

Options from the JavaScript library DataTable can be passed directly via renderDataTable argument options. For example, setting scrollX to be true allows tables to scroll.

Control height of datatableoutput in rstudio viewer

I think the simplest method would be to add height to dataTableOutput. You can play around with the number, and also try "rem", "px", etc. – "em" worked best for me. You might also want to try adding the width argument so the table scales when you resize the window, and perhaps try removing autoWidth from options, depending on how the final product looks.

---
title: "R Notebook"
output: html_notebook
---

```{r}
library(shiny)

ui <- fluidPage(
DT::dataTableOutput("tbl", height = "40em")
)
server <- function(input, output, session){
output$tbl = DT::renderDataTable(
mtcars,
server = FALSE,
selection = list(mode = "multiple", target = "column", selected = c(1)),
options = list(pageLength = 10, autoWidth = TRUE)
)
}

runApp(
appDir = shinyApp(ui, server),
launch.browser = rstudioapi::viewer
)
```

Screenshot of datatable

How to resize a datatable in order to fit it in a box() for shinyDashboard

You can simply add scrollX = TRUE to the datatable options:

library(shiny)
library(shinydashboard)

DF <- data.frame(replicate(50, runif(1000, 0, 10)))

ui <- fluidPage(box(
title = "A little taste of the dataset",
width = 12,
DT::dataTableOutput("myTable")
))

server <- function(input, output, session) {
output$myTable = DT::renderDataTable({
DT::datatable(
round(DF, 2),
rownames = TRUE,
extensions = 'Buttons',
options = list(
autoWidth = FALSE, scrollX = TRUE,
columnDefs = list(list(
width = "125px", targets = "_all"
)),
dom = 'tpB',
lengthMenu = list(c(5, 15,-1), c('5', '15', 'All')),
pageLength = 15,
buttons = list(
list(
extend = "collection",
text = 'Show More',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(50);
dt.ajax.reload();}"
)
),
list(
extend = "collection",
text = 'Show Less',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(10);
dt.ajax.reload();}"
)

)
)
)
)
})
}

shinyApp(ui = ui, server = server)

How can I reduce row height in DT datatables

If you add the pageLength= attribute you can set how many rows to show initially. And by adjusting the lengthMenu= c() you can also control the sizes of offered in the drop down, You can also turn search on or off with searching =FALSE

   library(DT)
datatable(d, options=list(
pageLength = 3,
lengthMenu = c(2, 12, 18),
searching= FALSE))%>%

formatStyle( 0, target= 'row',color = 'black', backgroundColor = 'yellow', fontWeight ='bold', lineHeight='70%')

And by using the helper functions you can set the style just as you would in traditional CSS on a webpage. Notice the last one, line-height should adjust the row height.

Edited: I moved all the code together for you to see how it works. Sorry I was not clearer up front. The %>%is necessary as is devtools::install_github("rstudio/DT") version of DT.



Related Topics



Leave a reply



Submit