Pivot table Output in Shiny
pivot-shiny.Rd
Display a pivot_table
in Shiny:
pivotOutput / renderPivot: adds a button to download pivot table in PowerPoint, Word and Excel.
pivot2Output / renderPivot2: display only the pivot table.
Usage
pivot2Output(outputId, width = "100%", ...)
renderPivot2(
expr,
width = 1,
background = "#81A1C1",
color = "#FFFFFF",
border = "#FFFFFF",
font_size = 14,
font_name = NULL,
labels = pivot_labels(),
formatter = pivot_formatter(),
env = parent.frame(),
quoted = FALSE
)
pivotOutput(outputId, width = "100%", export = export_labels(), ...)
export_labels(
export = "Export",
clipboard = "Copy to clipboard",
powerpoint = "Export to PowerPoint",
word = "Export to Word",
excel = "Export to Excel"
)
renderPivot(
expr,
width = 1,
background = "#81A1C1",
color = "#FFFFFF",
border = "#FFFFFF",
font_size = 11,
font_name = NULL,
labels = pivot_labels(),
formatter = pivot_formatter(),
label_value = "value",
env = parent.frame(),
quoted = FALSE,
filename = "export-pivot"
)
Arguments
- outputId
Output variable to read from.
- width
Value of the preferred width of the table in percent (
[0,1]
).- ...
Other arguments to pass to the container tag function. This is useful for providing additional classes for the tag.
- expr
An expression that generates a
pivot_table
.- background
Background color for the header and column(s) containing row(s).
- color
Text color for the header and column(s) containing row(s).
- border
Border color (applies to all table).
- font_size
Font size (applies to all table).
- font_name
Font name (applies to all table).
- labels
Custom labels for statistics, see
pivot_labels
.- formatter
Function to format content, see
pivot_formatter
.- env
The environment in which to evaluate
expr
.- quoted
Is
expr
a quoted expression (withquote()
)? This is useful if you want to save an expression in a variable.- export
Export labels, use
NULL
to disable all exports.- clipboard, powerpoint, word, excel
Labels to display in export menu, use
NULL
to disable specific format.- label_value
For Excel output, the label for variable containing the values.
- filename
A string of the filename to export WITHOUT extension, it will be added accordint to type of export.
Examples
library(shiny)
library(flexpivot)
data("nobel_laureates")
ui <- fluidPage(
tags$h2("Pivot table in Shiny"),
fluidRow(
column(
width = 6,
selectInput(
inputId = "row",
label = "Row",
choices = c("category", "gender", "birth_continent", "laureate_type"),
width = "100%"
)
),
column(
width = 6,
selectInput(
inputId = "col",
label = "Col",
choices = c("category", "gender", "birth_continent", "laureate_type"),
selected = "gender",
width = "100%"
)
)
),
pivotOutput("pivot")
)
server <- function(input, output, session) {
output$pivot <- renderPivot({
pivot_table(nobel_laureates, input$row, input$col)
}, background = "#A3BE8C")
}
if (interactive())
shinyApp(ui, server)