rstudio / htmltools

Tools for HTML generation and output
https://rstudio.github.io/htmltools/
215 stars 68 forks source link

body style has default padding: 40px, unclear how to change this value #297

Closed bbt-dev closed 2 years ago

bbt-dev commented 2 years ago

This is not a bug, but an undocumented aspect that I would like to ask about. By default, the html document created by the htmlwidgets::saveWidget which use htmltools (for example, htmlwidgets::saveWidget (reactable(iris))) has the following attributes in the body tag: <body class="vsc-initialized" style='margin: 9px; padding: 40px; "> that leads to excessive padding from the top of the page. I have tried to find any documentation how to change the "style='padding: 40px;'" but there is no documentation, and in the code of the save_html function no styles are defined. Please could you suggest how it is possible to change the style of the body tag and adjust the "padding: 40px" to the desired level?

cpsievert commented 2 years ago

I'm pretty sure the "correct" way to specify this padding is via htmlwidgets::sizingPolicy(browser.padding = ...)

bbt-dev commented 2 years ago

Thanks a lot, this works! Its a little bit strange that htmlwidgets::saveWidget could not accept an argument htmlwidgets::sizingPolicy(padding = 0), and the final solution is the following:

object2save <- reactable(iris)
object2save$sizingPolicy$padding <- 4
htmlwidgets::saveWidget(object2save, file = "example.html", 
            selfcontained = FALSE, libdir = "lib")