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

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

Closed
cpsievert opened this issue Oct 31, 2022 · 0 comments · Fixed by #281
Closed
Labels
bug Something isn't working
Milestone

Comments

@cpsievert
Copy link
Contributor

cpsievert commented Oct 31, 2022

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

reactable/R/reactable.R

Lines 220 to 221 in f6a4e0a

width = "auto",
height = "auto",

reactable/R/reactable.R

Lines 718 to 724 in f6a4e0a

htmlwidgets::createWidget(
name = "reactable",
reactR::reactMarkup(component),
width = width,
height = height,
# Don't limit width when rendered inside an R Notebook
sizingPolicy = htmlwidgets::sizingPolicy(knitr.figure = FALSE),

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:

reactable/R/reactable.R

Lines 710 to 716 in f6a4e0a

if (static) {
# HACK: widget_html is the only way to customize the widget HTML, but it
# doesn't have access to the widget attributes. To work around this, we attach
# the widget attributes as an attribute on width, which just happens to be passed
# as-is for static rendered HTML widgets.
attr(width, "ssrGetAttribs") <- function() component$attribs
}

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 )

cpsievert added a commit to cpsievert/reactable that referenced this issue Nov 1, 2022
…use sizingPolicy()'s defaultWidth/defaultHeight to supply the 'auto' defaults). Also leverage as.tags() to implement static rendering
@glin glin closed this as completed in #281 Nov 13, 2022
@glin glin added this to the v0.4.0 milestone Nov 20, 2022
@glin glin added the bug Something isn't working label Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants