glin / reactable

Interactive data tables for R
https://glin.github.io/reactable
Other
612 stars 79 forks source link

reactable() doesn't respect `htmlwidget::sizingPolicy()`'s `viewer.fill` (or `browser.fill`) #280

Closed cpsievert closed 1 year ago

cpsievert commented 1 year ago

The reason why reactable() currently doesn't fill the RStudio IDE viewer pane (which is the default {htmlwidgets} behavior) is that reactable() passes a default value of "auto" to createWidget()'s height/width

https://github.com/glin/reactable/blob/f6a4e0a23aba43dbc820e252d06e795c9092d977/R/reactable.R#L220-L221

https://github.com/glin/reactable/blob/f6a4e0a23aba43dbc820e252d06e795c9092d977/R/reactable.R#L718-L724

This is because htmlwidgets::createWidget() assumes non-NULL values are user specified values. This isn't very well documented, but you can see evidence of this in http://www.htmlwidgets.org/develop_intro.html as well as the code {htmlwidgets} uses to resolve sizingPolicy():

https://github.com/ramnathv/htmlwidgets/blob/cb052ac613ffe13bd6a3f4b6e9333002e72b59d8/R/sizing.R#L193-L194

I've also noticed that we can't simply change width/height's default in reactable to NULL, because of this:

https://github.com/glin/reactable/blob/f6a4e0a23aba43dbc820e252d06e795c9092d977/R/reactable.R#L710-L716

However, I think I have an idea for removing that "hack", which will allow for non-NULL width.

(P.S., I ran across this because we're currently working on a new fill setting in htmlwidgets::sizingPolicy() that allows widgets to fill a container marked with htmltools::bindFillRole(container = TRUE), which will power "resizable cards" https://rstudio.github.io/bslib/articles/cards.html#responsive-sizing )