gt (version 0.2.2)

gt_output: Create a gt display table output element for Shiny

Description

Using gt_output() we can render a reactive gt table, a process initiated by using the render_gt() function in the server component of a Shiny app. The gt_output() call is to be used in the Shiny ui component, the position and context wherein this call is made determines the where the gt table is rendered on the app page. It's important to note that the ID given during the render_gt() call is needed as the outputId in gt_output() (e.g., server: output$<id> <- render_gt(...); ui: gt_output(outputId = "<id>").

Usage

gt_output(outputId)

Arguments

outputId

An output variable from which to read the table.

Function ID

12-2

Details

We need to ensure that we have the shiny package installed first. This is easily by using install.packages("shiny"). More information on creating Shiny apps can be found at the Shiny Site.

See Also

Other Shiny functions: render_gt()

Examples

Run this code
# NOT RUN {
library(shiny)

# Here is a Shiny app (contained within
# a single file) that (1) prepares a
# gt table, (2) sets up the `ui` with
# `gt_output()`, and (3) sets up the
# `server` with a `render_gt()` that
# uses the `gt_tbl` object as the input
# expression

gt_tbl <-
  gtcars %>%
  gt() %>%
  cols_hide(contains("_"))

ui <- fluidPage(

  gt_output(outputId = "table")
)

server <- function(input,
                   output,
                   session) {

  output$table <-
    render_gt(
      expr = gt_tbl,
      height = px(600),
      width = px(600)
    )
}

if (interactive()) {
  shinyApp(ui, server)
}

# }

Run the code above in your browser using DataCamp Workspace