Skip to content

Commit

Permalink
dataTableOutput()'s width and height now default to NULL (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert authored Oct 20, 2022
1 parent 248df7d commit e02783c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CHANGES IN DT VERSION 0.27

- `dataTableOutput()`'s `height` and `width` now defaults to `NULL`, allowing it have more flexible default sizing behavior, which will be primarily useful in combination with `{bslib}`'s new `card()` API (thanks, @cpsievert, #1026).

# CHANGES IN DT VERSION 0.26

- Upgraded DataTables to v1.12.1.
Expand Down
2 changes: 1 addition & 1 deletion R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' }
#' )
#' }
dataTableOutput = function(outputId, width = '100%', height = 'auto') {
dataTableOutput = function(outputId, width = NULL, height = NULL) {
htmltools::attachDependencies(
htmlwidgets::shinyWidgetOutput(
outputId, 'datatables', width, height, package = 'DT'
Expand Down
11 changes: 11 additions & 0 deletions inst/htmlwidgets/css/datatables.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
dataTableOutput() no longer supplies a default size via inline styles, so define those defaults here.
We also define `flex-basis` since when dataTableOutput() (and thus htmlwidgets::shinyWidgetOutput()) has height = NULL, it receives a CSS class which effectively amounts to `flex: 1 1 auto` in a `{bslib}` app (to make it so widgets can stretch vertically inside of resizable card()s). That's mostly fine, but `fillContainer=TRUE`+`height:auto`+`flex-basis:auto` is problematic for DT since the table wants to fit the parent but the parent wants to fit the table. Thankfully, setting `flex-basis` to a fixed size seems to resolve that issue.
*/

.datatables.html-widget {
width: 100%;
height: auto;
flex-basis: 400px;
}
5 changes: 4 additions & 1 deletion inst/htmlwidgets/datatables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ dependencies:
- name: datatables-css
version: 0.0.0
src: "htmlwidgets/css"
stylesheet: datatables-crosstalk.css
stylesheet: [
datatables.css,
datatables-crosstalk.css
]
4 changes: 2 additions & 2 deletions man/dataTableOutput.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e02783c

Please sign in to comment.