Controlling table width in Shiny dataTableOutput

I cannot control the datatable width that I added to the brilliant application using the dataTableOutput() function. I tried to use the width parameter inside the function, but it does not change anything in the output, and there is no error. This does not tell me that it ignores the width parameter.

 library(shiny) library(shinythemes) ui <- fluidPage(theme = shinytheme("Spacelab"), fluidRow( column(6,dataTableOutput(outputId = "table")), column(6,p(textOutput("para"))) ) ) server <- function(input, output){ df <- as.data.frame(matrix(0, ncol = 15, nrow = 20)) output$table <- renderDataTable({df}) output$para <- renderText({ text <- rep(x = "Hello World",1000) }) } shinyApp(ui = ui,server = server) 
+5
source share
2 answers

dataTableOutput has no argument width. You can use the column within fluidRow the width of the argument by giving an integer from 1 to 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) 

Parameters from the JavaScript DataTable library can be passed directly through renderDataTable arguments. For example, if you set scrollX to true, this allows you to scroll through tables.

+11
source

If you use the "DT" R package and the corresponding DT::dataTableOutput and DT::renderDataTable , you can use the "width" option with these calls, which, apparently, can be either% (for example, width = "100%" ) or pixels (width = 300) that should get you the control you need.

See: https://rstudio.imtqy.com/DT/shiny.html

Note from this page:

Important: Be sure to use the DT :: prefix when calling dataTableOutput and renderDataTable, so that the DT versions of these functions are guaranteed to be named, not obsolete Shiny versions. If you make sure that the library (DT) after the library (brilliant), as a rule, the DT versions should simply override the brilliant versions if you do not use DT :: prefix (if in doubt, use this prefix until we completely remove these functions from brilliant)

+3
source

All Articles