-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
htmlDependency used in dynamic UI breaks when script
is provided as a named list instead of a string
#3345
Comments
This is not a problem only for modules, this seems to be an issue whenever
|
script=list(...)
script
is provided as a named list instead of a string
@schloerke @wch my original title and description were much more complicated than needed. I've simplified the problem, so hopefully it's easier to understand now and will get looked at :) |
Thank you for the great reprexes!! When put in the UI, it is eventually rendered using In dynamic shiny/srcjs/output_binding_html.js Lines 182 to 187 in b57cb6c
When this gets fixed, it either needs to leverage This app provides a work around using the library(shiny)
ui <- fluidPage(
uiOutput("test")
)
server <- function(input, output, session) {
output$test <- renderUI({
ret <- htmltools::attachDependencies(
"test",
htmltools::htmlDependency(
name = "test",
version = "1.0.0",
src = c(href = "https://cdn.jsdelivr.net/gh/daattali/htmldependencybug"),
script = list(src = "test.js", type = "module")
)
)
# ... reformat into tags ...
deps <- htmltools::htmlDependencies(ret)
ret_no_deps <- ret
htmltools::htmlDependencies(ret_no_deps) <- NULL
htmltools::tagList(
htmltools::tags$head(
htmltools::renderDependencies(deps)
),
ret_no_deps
)
})
}
shinyApp(ui, server) |
Thanks for finding out the culprit @schloerke Your workaround does work for the simple case I mentioned here, but it does not work for my real usecase. I may be wrong, but it might be I'm using local files rather than www URLs, and I haven't explicitly used In either case, I see you've added this to the next release milestone, so I prefer to wait for the fix rather than a hacky workaround |
* Close #3345: correctly render script tags defined as list() objects * implement boolean attrs; use vanilla JS * Update news * avoid toggleAttribute * yarn lint (GitHub Actions) * code review Co-authored-by: cpsievert <[email protected]>
Not sure if this should be filed under {htmltools} or {shiny} - I filed it here because the interaction with shiny is what's broken from what I can tell.
To use
htmlDependency
to load a javascript module, we need to usescript = list(src = "test.js", type = "module")
. This works fine when the dependency is resolved from the UI, but it seems to parse incorrectly when done dynamically. Example:The above code works - you'll see a javascript alert.
But if the content is loaded dynamically -- either using insertUI or using a uiOutput/renderUI -- then it breaks. Example:
The page loads but the javascript module isn't loaded. Looking at the page source, I can see that it's trying to load a script with src of
https://cdn.jsdelivr.net/gh/daattali/htmldependencybug/%5Bobject%20Object%5D
- this is what's causing this bug. It seems that shiny does not know how to deal with thescript
argument being a named list, even though a named list is allowed according to the documentation.The text was updated successfully, but these errors were encountered: