Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dataTableOutput()'s width and height now default to NULL #1026

Merged
merged 2 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.