HtmlWidgets - including DT - how do they render in static Rmarkdown reports?

We've been building a custom RMarkdown renderer recently.

We built this using the docs in 18.2 Fully custom formats | R Markdown: The Definitive Guide and the flexdashboard code as an example to follow.

It's working well, except we've hit some issues with HtmlWidgets like DT occasionally not rendering.

Looking at the HTMLWidgets js code - htmlwidgets/htmlwidgets.js at 9827b5fbf6e184f67f5957a9769a46227cd7bf5a · ramnathv/htmlwidgets · GitHub it seems like what is happening in our case is that the static bindings for DT elements haven't been registered when the default maybeStaticRenderLater() is called (I think it's called by "DOMContentLoaded" event)

Looking at the FlexDashboard code, they've got a workaround in this area - they trigger a "shown" event on a timeout - flexdashboard/flexdashboard.js at b3cb4a396bdfd2fc63a0f000e501fd53fe0122b8 · rstudio/flexdashboard · GitHub

We've managed to get our DT tables to show using a similar type of "timeout" and "show" approach, but we have seen it fail (especially for large rendered HTML files) and it feels like there should be some more definite way to ensure that the static HTMLWidgets bindings get executed.

Does anyone have any suggestions/ideas about what should be done here? Is there a DOM, HTMLWidgets, DT or RMarkdown event we can listen for? Is there some dependency ordering we should enforce within the rendered HTML? Or anything else?

Thanks for any suggestions

Stuart
and looking at the , it seems like there's flexdashboard code

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.