| withBones | R Documentation |
Shows a grey placeholder in the shape of the content while the output loads for the first time. When the output calculates again, the old content stays on the screen and is dimmed. The user is possibly reading that content, and grey boxes in its place would remove information and add none.
withBones(
ui,
type = NULL,
rows = 6L,
cols = 4L,
lines = 3L,
n = 3L,
height = NULL,
animation = NULL,
stale = NULL,
delay = NULL,
min_time = NULL,
remember = NULL,
skeleton = NULL
)
ui |
A Shiny output, such as |
type |
The shape of the skeleton: |
rows, cols |
The number of body rows and columns, when |
lines |
The number of lines, when |
n |
The number of cards or values, when |
height |
A CSS height for the placeholder, or a number of pixels, as
in Shiny. |
animation |
|
stale |
|
delay |
The time in milliseconds before the skeleton, or the
dimming, appears. A load that ends sooner shows nothing, so a fast
output does not flicker. The space of the content is kept from the
start. |
min_time |
The shortest time in milliseconds that the skeleton, or
the dimming, stays on the screen once it has appeared. A load that ends
a moment after |
remember |
|
skeleton |
Your own placeholder, in place of a built-in shape: a tag
or a tag list, made of |
ui, in a placeholder container.
The shape comes from the output that you give: plotOutput() gets the
shape of a chart, tableOutput() gets rows and columns, and
textOutput() gets lines of text. Use type to set a different shape.
You must do this for uiOutput(), because its content is not known
before it arrives.
A plotOutput() gets the shape of a bar chart. If the chart is of
another kind, give that kind: "line", "scatter", "area",
"histogram", "pie" or "heatmap". The output cannot tell, because
renderPlot() decides the kind later, on the server.
A table from a table package gets the shape of that package, found from
its output: DT::DTOutput() gets "dt", reactable::reactableOutput()
gets "reactable", gt::gt_output() gets "gt", and
rhandsontable::rHandsontableOutput() gets "rhandsontable". Each shape
copies the parts of its package, such as the search box of DT. Set rows
to the number of rows on a page: DT and reactable show 10 by default.
Before gt 1.0.0, gt_output() did not mark its output as a gt table, so
with an older gt, give type = "gt".
A visualisation widget gets the shape of its kind, found from its output
in the same way. A map (leaflet, tmap, mapview, mapdeck and others) gets
"map". A network or a diagram (visNetwork, DiagrammeR, networkD3,
collapsibleTree) gets "network". timevis gets "timeline", wordcloud2
gets "wordcloud", and dygraphs gets "line". ggmap and a ggplot2 map
draw into a plotOutput(), so give them type = "map".
A plotly, echarts4r or highcharter output can draw any kind of chart. With
no type, it finds its kind by itself, but only when its first value
arrives in the browser: the spec of the chart names the kind of each
series. The first skeleton thus has the bar shape. The next loads, with
stale = FALSE, show the shape of the kind: "bar", "line", "area",
"scatter", "histogram", "pie", "heatmap", "map", "network" or
"wordcloud". With remember, the kind is also stored in the browser, so
on the next visit the first skeleton has that shape too. The first series
that names a kind decides. A chart of a kind with no shape, such as a box
plot, keeps the bar shape. A type that you give always wins. Other
widgets that can draw any chart, such as ggiraph, keep the bar shape: give
their kind with type.
When no built-in shape fits, give your own with skeleton. Build it from
bones_block(), a grey block that takes the colours and the animation of
bones, and lay the blocks out with any tags. The tags at the top level
stack with a small gap. The placeholder behaves as a built-in shape does: it
waits for delay, it stays for min_time, it keeps the space of the
content, and the old content stays when stale is TRUE.
The wrapper keeps the space of the output until the content arrives, so
the page does not move. If the output sets its own height, as
plotOutput() does, the wrapper uses that height. If not, the height
comes from rows, lines or n, or you can set it with height. When
the content arrives, the content sets the height.
if (requireNamespace("shiny", quietly = TRUE)) {
library(shiny)
withBones(plotOutput("chart"))
withBones(tableOutput("results"), rows = 8, cols = 5)
withBones(uiOutput("cards"), type = "cards", n = 4)
withBones(plotOutput("trend"), type = "line")
# Your own placeholder: an avatar and two lines of text.
withBones(
uiOutput("profile"),
skeleton = div(
style = "display: flex; gap: 1rem; align-items: center;",
bones_block("3rem", "3rem", shape = "circle"),
div(
style = "flex: 1; display: grid; gap: 0.5rem;",
bones_block("60%"), bones_block("40%")
)
)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.