Table
#| standalone: true
#| components: [viewer]
#| viewerHeight: 200
library(shiny)
library(bslib)
library(palmerpenguins)
ui <- page_fluid(
tableOutput("table")
)
server <- function(input, output) {
output$table <- renderTable(penguins, striped = TRUE)
}
shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)
library(palmerpenguins)
ui <- page_fluid(
tableOutput("table")
)
server <- function(input, output) {
output$table <- renderTable(penguins, striped = TRUE)
}
shinyApp(ui = ui, server = server)Relevant Functions
-
tableOutput
tableOutput(outputId) -
renderTable
renderTable(expr, striped = FALSE, hover = FALSE, bordered = FALSE, spacing = c("s", "xs", "m", "l"), width = "auto", align = NULL, rownames = FALSE, colnames = TRUE, digits = NULL, na = "NA", ..., env = parent.frame(), quoted = FALSE, outputArgs = list())
Details
To make a reactive table, follow three steps:
Call
tableOutput()in the UI of your app to create a div in which to display the table. Where you call this function within the UI functions will determine where the table will appear within the layout of the app. Set theoutputIdargument oftableOutput()to a unique value.Within the server function, call
renderTable()and save its output as an element of theoutputlist. Name the element after theoutputIdused above. For example,output$table <- renderTable().tableOutput()will display the value of theoutputelement whose name matches itsoutputId.Pass
renderTable()either a table object, or a block of code, surrounded with{}, that returns a table. The table must R object that can be used withxtable::xtable().Optionally, use the other arguments (e.g.,
striped,hover) ofrenderTable()to control the appearance and behavior of the table.