
A summary table whose rows explain where they came from
Source:R/output-table.R
whenceTableOutput.RdwhenceTableOutput() shows a table, such as the result of
group_by(region) |> summarise(total = sum(revenue)). The viewer clicks
the first cell of a row (or presses Enter or Space on it) to open the panel
of that row: how many rows of its group each step removed, the code that
makes the row, and the rows of the group. A link under the table opens the
panel of the table as a whole.
Usage
whenceTableOutput(outputId, label = NULL)
renderWhenceTable(
expr,
format = NULL,
env = parent.frame(),
quoted = FALSE,
outputArgs = list()
)Arguments
- outputId
The output id.
- label
Text to show before the value, or
NULLfor none. The panel uses it in its heading too.- expr
A pipeline that ends in a summary table.
- format
NULL, a function for every number column that is not a group column, or a named list of functions, one for each column to change, such aslist(total = scales::label_dollar()).- env
The environment in which to evaluate
expr.- quoted
Is
expralready quoted? UseTRUEwhen you give an expression made withquote().- outputArgs
A list of arguments for
whenceOutput(), such aslabel, when the render is used in an R Markdown document withruntime: shiny.
Value
whenceTableOutput() gives an HTML tag for the UI.
renderWhenceTable() gives a render function for the server.
Details
renderWhenceTable() makes the table. Give it a pipeline that ends in a
summary, as for whence_table(). The table itself is sent with the render.
The panel of a row needs one trip to the server, because it replays the
steps for its group.
The rows can be explained when the group columns of the last summary step are in the table. The table shows at most 500 rows.
Examples
whenceTableOutput("by_region", label = "Revenue by region")
#> <div id="by_region" class="whence-output whence-table-output" data-label="Revenue by region">
#> <div class="whence-label">Revenue by region</div>
#> <div class="whence-slot"></div>
#> </div>
if (interactive() && requireNamespace("dplyr", quietly = TRUE)) {
library(shiny)
library(dplyr, warn.conflicts = FALSE)
ui <- fluidPage(whenceTableOutput("by_cyl", label = "Mean mpg by cylinders"))
server <- function(input, output, session) {
output$by_cyl <- renderWhenceTable(
mtcars |>
filter(hp > 90) |>
group_by(cyl) |>
summarise(mpg = mean(mpg)),
format = list(mpg = function(x) format(round(x, 1)))
)
}
shinyApp(ui, server)
}