Skip to contents

whenceTableOutput() 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 NULL for 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 as list(total = scales::label_dollar()).

env

The environment in which to evaluate expr.

quoted

Is expr already quoted? Use TRUE when you give an expression made with quote().

outputArgs

A list of arguments for whenceOutput(), such as label, when the render is used in an R Markdown document with runtime: 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)
}