Table (reactable)
#| standalone: true
#| components: [viewer]
#| viewerHeight: 200
library(shiny)
library(bslib)
library(reactable)
library(palmerpenguins)
ui <- page_fluid(
reactableOutput("table")
)
server <- function(input, output) {
output$table <- renderReactable({reactable(penguins)})
}
shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)
library(reactable)
library(palmerpenguins)
ui <- page_fluid(
reactableOutput("table")
)
server <- function(input, output) {
output$table <- renderReactable({reactable(penguins)})
}
shinyApp(ui = ui, server = server)
Relevant Functions
-
reactableOutput
reactableOutput(outputId, width = "auto", height = "auto", inline = FALSE)
-
renderReactable
renderReactable(expr, env = parent.frame(), quoted = FALSE)
Details
To make a reactive interactive table with reactable, follow these steps:
Install (
install.packages("reactable")
) and load (library(reactable)
) the reactable package.Call
reactableOutput()
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 gt table will appear within the layout of the app. Set theoutputId
argument ofreactableOutput()
to a unique value.Optionally, use the
height
,width
, andinline
arguments ofreactableOutput()
to control the appearance and positioning of the table.Within the server function, call
renderReactable()
and save its output as an element of theoutput
list. Name the element after theoutputId
used above. For example,output$table <- renderReactable()
.reactableOutput()
will display the value of theoutput
element whose name matches itsoutputId
.Pass
renderReactable()
a block of code, surrounded with{}
, that returns a reactable widget. Usereactable()
’s arguments to control the appearance and behavior of the table.