Skip to content

runtime: shiny in Rmarkdown doesn't know how to handle htmlDependency() #375

@daattali

Description

@daattali

If an htmltools::htmlDependency() gets added to the UI of a regular shiny app, shiny knows how to treat it as a dependency and add the scripts/css files to the head.

If it gets added to a shiny-powered Rmarkdown, it gets converted to text.

Example:

The following shiny app adds the fontawesome dependencies, and therefore the icon shows up

library(shiny)

ui <- fluidPage(
  fontawesome::fa_html_dependency(),
  tags$i(class = "fas fa-pencil")
)

server <- function(input, output, session) {}

shinyApp(ui, server)

The following Rmarkdown treats the dependency as text

---
runtime: shiny
---

```{r}
fontawesome::fa_html_dependency()
tags$i(class = "fas fa-pencil")
```

The rmarkdown version does work if I wrap the dependency in an empty attachDependencies():

htmltools::attachDependencies(HTML(''), fontawesome::fa_html_dependency())

This is technically not a bug because the documentation of htmlDependency() does say that these objects are meant to go inside attachDependencies(), but in practice because it works in regular shiny apps I would expect it to also work in Rmd.

Metadata

Metadata

Assignees

No one assigned

    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