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

Allow to add specific shiny-prerendered parts in HTML template #2064

Merged
merged 12 commits into from
Mar 4, 2021

Conversation

cderv
Copy link
Collaborator

@cderv cderv commented Mar 3, 2021

This should fix #2060 and help solve rstudio/learnr#499 and rstudio/learnr#502 by modifying the leanr template.

Instead of adding the placeholder for head content required by htmltools::renderDocument() to the end of the <head>, we check if it is already in the rendered HTML.

This come with a feature to add content in a Pandoc template conditionnaly to shiny_prerendered rendering. A new pandoc variable shiny-prerendered will be set and pass to Pandoc that will allow $if(shiny-prerendered)$ clause in a Pandoc template.

All html templates in rmarkdown gains addition of <!-- HEAD_CONTENT --> placeholder using this. {{ headContent() }} is not used because we don't want to pass the all HTML file to htmltools::htmlTemplate(). It seems htmltools::renderDocument() expect this special comment token anyway, so it seems fine to use it directly.

With this change, it will be a better fix for #1912 than just #1942 allow greater flexibility for template makers. This will allow learn to add the same part in the template and have html dependencies loaded where needed in the resulting html file.

cc @schloerke @gadenbuie @jcheng5

Copy link
Contributor

@schloerke schloerke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

R/shiny_prerendered.R Show resolved Hide resolved
@cderv
Copy link
Collaborator Author

cderv commented Mar 3, 2021

  • still tests to add before merging.

@cderv cderv self-assigned this Mar 3, 2021
@cderv
Copy link
Collaborator Author

cderv commented Mar 4, 2021

@gadenbuie would that work for you too ?
You would need to add the if close in the learnr template and it should fix it.

Copy link
Member

@gadenbuie gadenbuie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@cderv cderv changed the title Allow to add specific shiny-prenrendered parts in HTML template (like head content placeholder) Allow to add specific shiny-prerendered parts in HTML template Mar 4, 2021
@cderv cderv merged commit 61db7a9 into master Mar 4, 2021
@cderv cderv deleted the shiny-header-template branch March 4, 2021 16:47
cderv added a commit to rstudio/flexdashboard that referenced this pull request Jun 22, 2021
cpsievert pushed a commit to rstudio/flexdashboard that referenced this pull request Jun 23, 2021
* Add HEAD placeholder in html template for shiny_prerendered

This follows change in rstudio/rmarkdown#1942 and rstudio/rmarkdown#2064

* update NEWS
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong order of dependencies in header for shiny prerendered document ?
3 participants