add default (pre-reactivity) HTML content
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 5.7k
- Forks
- 1.9k
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 2
Description
Typically, some of the dynamic-output (uiOutput, htmlOutput) elements take up zero space on instantiation and "pop out" when reactivity or requirements catch up. It may be preferred (from a UX standpoint) to have that space filled with something, both to keep the surrounding content stable as well as to (perhaps) hint at what will be coming into that spot. Obviously shiny cannot always know what that space looks like, but the author can easily provide a best-guess space-filler.
For instance, if a module exports an icon that indicates (by color or icon, perhaps) the status of something. Typically, the setup would be:
shinyApp(
ui = shinyUI(
pageWithSidebar(
headerPanel("Outputs"),
sidebarPanel(
"before",
htmlOutput("statusicon"),
"after"
),
mainPanel()
)
),
server = function(input, output, session) {
output$statusicon <- renderUI({
Sys.sleep(1)
icon("check-square")
})
}
)
I suggest a helper-function that allows for default values:
#' @param func function for HTML rendering, such as htmlOutput
#' @param ... arguments passed to the function
defaultOutput <- function(expr, default = list()) {
out <- force(expr)
out$children <- htmltools::tags$div(default)
out
}
shinyApp(
ui = shinyUI(
pageWithSidebar(
headerPanel("Outputs"),
sidebarPanel(
"before",
defaultOutput(htmlOutput("statusicon"), default = icon("square")), # <--- the only change
"after"
),
mainPanel()
)
),
server = function(input, output, session) {
output$statusicon <- renderUI({
Sys.sleep(1)
icon("check-square")
})
}
)
The rendered content seems straight-forward and consistent:
htmlOutput("statusicon")
# <div id="statusicon" class="shiny-html-output"></div>
defaultOutput(htmlOutput, "statusicon", default = icon("square"))
# <div id="statusicon" class="shiny-html-output">
# <div>
# <i class="fa fa-square"></i>
# </div>
# </div>
This can be trivially extended to delayed-plots with something like
defaultOutput(
plotOutput, "someplot",
default = tags$div(style = "width:100px;height:200px")
)
This function is trivial and barely has any substance, and it should probably check before over-writing $children. But the point is to make the function intuitive and clear to hold space before reactivity introduces real content.
Thoughts?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing htmlOutput and renderUI behavior, then inspect how dynamic HTML output is rendered and replaced. The change would be complete when authors can provide default content that occupies the output area before reactive content arrives, without overwriting existing children unexpectedly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html, r
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100