ramnathv / htmlwidgets

HTML Widgets for R
http://htmlwidgets.org
Other
792 stars 205 forks source link

HtmlWidgets why is a timeout needed (what is the correct timeout) in static reports? #446

Open slodge opened 2 years ago

slodge commented 2 years ago

We've got some issues at present with HtmlWidgets sometimes not showing in RMarkdown reports when using a custom RMarkdown renderer.

Apologies for not supplying a reproducible sample at present - but we're finding reproducibility is fairly tricky! There seems to be something "timing" related as to why some HtmlWidgets get shown and some don't, and the same rendered Html files will sometimes work and sometimes (rarely) fail.

This seems to be something to do with maybeStaticRenderLater and we've found one workaround which helps with this - this is based on some code we found in the FlexDashboard repo - they trigger a "shown" event on a timeout - flexdashboard/flexdashboard.js at b3cb4a396bdfd2fc63a0f000e501fd53fe0122b8 · rstudio/flexdashboard · GitHub

Is a timeout and "shown" event the correct way to go here? Does anyone have any suggestions/ideas about what else should be done here? Is there a DOM, HTMLWidgets, DT or RMarkdown event we can listen for instead of using a timeout? Is there some dependency ordering we should enforce within the rendered HTML? Or any other ideas at all really?

Thanks for any suggestions

Originally asked in: https://community.rstudio.com/t/htmlwidgets-including-dt-how-do-they-render-in-static-rmarkdown-reports/149139