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
)
```
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
Shiny Dynamic Filter Variable Selection and Display of Variable Values for Selection
How to Extract All the Rows If a Level in One Column Contains All the Levels of Another Column in R
Selection of Activity Trace in a Chart and Display in a Data Table in R Shiny
Change Size of Axes Title and Labels in Ggplot2
How to Play Birthday Music Using R
Shift Legend into Empty Facets of a Faceted Plot in Ggplot2
Convert a Row of a Data Frame to Vector
Get the Path of Current Script
How to Increase the Size of Points in Legend of Ggplot2
Extract Knots, Basis, Coefficients and Predictions for P-Splines in Adaptive Smooth
Run R Script from .Bat (Batch File)
How to Put the Labels Outside of Piechart
R Markdown: How to Make Text Float Around Figures
R: Split Variable Column into Multiple (Unbalanced) Columns by Comma
R: Losing Column Names When Adding Rows to an Empty Data Frame