Skip to content

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

Merged
cderv merged 12 commits into
masterfrom
shiny-header-template
Mar 4, 2021
Merged

cderv merged 12 commits into
masterfrom
shiny-header-template

Conversation

@cderv

@cderv cderv commented Mar 3, 2021

Copy link
Copy Markdown
Collaborator

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

@schloerke schloerke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

Comment thread R/shiny_prerendered.R Resolved
@cderv

cderv commented Mar 3, 2021 •

Copy link
Copy Markdown
Collaborator Author
  • still tests to add before merging.

@cderv cderv self-assigned this Mar 3, 2021
@cderv

cderv commented Mar 4, 2021

Copy link
Copy Markdown
Collaborator Author

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

@gadenbuie gadenbuie left a comment

Copy link
Copy Markdown
Member

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