Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] singleton function - htmltools::singleton #42

Open
Polkas opened this issue Aug 11, 2022 · 3 comments
Open

[feature] singleton function - htmltools::singleton #42

Polkas opened this issue Aug 11, 2022 · 3 comments

Comments

@Polkas
Copy link

Polkas commented Aug 11, 2022

I think the htmltools::singleton functionality is very useful, especially when developing shiny modules.
Please consider adding it in the python version.

@cpsievert
Copy link
Collaborator

cpsievert commented Aug 11, 2022

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!

@Polkas
Copy link
Author

Polkas commented Aug 11, 2022

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.

@cpsievert
Copy link
Collaborator

cpsievert commented Aug 11, 2022

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 posit-dev/py-shiny#127, most users won't need to know about head_content()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants