Skip to content

Wrong order of dependencies in header for shiny prerendered document ? #2060

Closed

Description

@cderv

This follows #1912 fixed by #1942.

Following the merge of the PR, @gadenbuie have seen issues in learnr possibly related to this:

Putting his comment here too: #1942 (comment)

Adding the additional dependencies at the end of <head> feels like the right thing to do but, unfortunately, it breaks previous behavior. Before this change the served document structure was (essentially):

shiny boilerplate:
|- head
|- body
   |- full prerendered document
      |- head
      |- body

so the dependencies added by shiny were in the first <head> tag and the document's dependencies appeared in the second <head> tag. When reconciled by the browser, this ends up being the same as

browser DOM
|- head
   |- shiny dependencies
   |- prerendered doc dependencies

In learnr, for example, this creates a situation where the scripts and dependencies in the tutorial's pandoc template appear before the tutorial dependencies provided by learnr.

This may be the correct behavior and we can adjust in learnr, but I suspect there are other templates that take advantage of the implicit ordering of dependencies in the previous behavior.

Currently, format like learnr assumes shiny dependencies is loaded before documents dependencies. This is the previous behavior. Maybe we should stick with that.

This issue is to track discussion in which order the dependencies should be added. Currently, using shiny templating when the page is render, the dependencies are added at the end of the head

# add placeholder for additional dependencies at the end of the <head> element
# using a template expansion expected by shiny (usually done in shiny:::renderPage)
sub('</head>',
paste0('\n', htmltools::htmlTemplate(text_ = "{{ headContent() }}"), '\n</head>'),
html_with_deps,
fixed = TRUE,
useBytes = TRUE)

Should it be at the top of the head ? Or is it more complex than that to correctly handle document head without shiny header ?

cc @schloerke @gadenbuie

Activity

  1. cderv commented on Mar 1, 2021

    @cderv
    CollaboratorAuthor

    Some takes on what we discussed:

    • With shiny prerendered, dependencies are not included in header-includes at Pandoc rendering. They are inserted in the HTML later on when building the shiny ui.
    • Currently, everything will be put at the end of with no control. This is what causes issue with learnr for example as the template head uses script requiring JQuery.
    • So we have a difference about where the dependencies are in the when using no runtime or using runtime shiny prerendered.

    To insert the content in a correct place in the header:

    • We could sub into the top of the head, instead of the bottom
    • We could make the html rendered by rmarkdown a full document shiny template as expected by shiny - this means containing the <!-- HEAD_CONTENT --> special comment that shiny::renderPage expects.

    Going for the latter would allow more control by template producer. We could make this conditional in the pandoc template using a pandoc variable that would be activated when render happens for shiny_prerendered.

    Thanks @schloerke and @gadenbuie for the discussion and all the inputs!

  2. self-assigned this
    on Mar 1, 2021
  3. added a commit that references this issue on Mar 4, 2021
    61db7a9
  4. github-actions commented on Sep 7, 2021

    @github-actions

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

  5. locked as resolved and limited conversation to collaborators on Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions