Open Polkas opened 2 years ago
Have you come across ui.head_content()
? We were hoping that could be a replacement for singleton()
, which more often than not is used for making sure some content only appears in the <head>
once (which head_content()
is designed to do). If you have other situations where you find singleton()
useful, please let us know!
Thanks for the quick answer. So the market standard is that most often styles are located at the head but the javascript code at the body (usually bottom). I do not see a sibling body_content function so how I could protect myself against repeated body calls which comes from e.g. a separate module (which could be called many times). If you will document that the styles and javascript is recommended to be located at the head with head_content then you could close the issue.
So the market standard is that most often styles are located at the head but the javascript code at the body (usually bottom).
Good point. From what I understand, the convention for placing JS code towards the bottom of the body is mostly (entirely?) to guarantee that the code executes after the DOM is ready, but that can also be done by adding a defer
attribute to the script tag (or similar).
If you will document that the styles and javascript is recommended to be located at the head with head_content then you could close the issue.
For now this seems like a good idea/recommendation, but let's also keep in mind that once we have https://github.com/rstudio/py-shiny/pull/127, most users won't need to know about head_content()
I think the
htmltools::singleton
functionality is very useful, especially when developing shiny modules. Please consider adding it in the python version.