0

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?

boris
  • 13
  • 5

2 Answers2

1

style="" should be double quotes. You have a single quote and a double.

<body class="vsc-initialized" style="margin: 9px; padding: 40px;">

You can try overwriting with !important

.vsc-initialized{padding: 0px!important;}
  • Thnaks a lot for your suggestion! It will work, but this CSS-based approach means I need to define the style manually each time. I would like to find a solution that alows to define padding during the execution of htmlwidgets::saveWidget. – boris Nov 04 '21 at 09:36
1

The direction to the solution has been provided by cpsievert in this thread

The final solution is the following:

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