Skip to content

Instantly share code, notes, and snippets.

@DeepanshKhurana
Created March 25, 2023 08:43
Show Gist options
  • Save DeepanshKhurana/c81643a806ce0ec0c977b8742c9810dd to your computer and use it in GitHub Desktop.
Save DeepanshKhurana/c81643a806ce0ec0c977b8742c9810dd to your computer and use it in GitHub Desktop.
Using Reactable with YAML
# Loading Libraries ----
library(reactable)
library(yaml)
library(shiny)
# Generate Reactable Function ----
generate_reactable <- function(data,
table_type,
yaml_file_path = "config.yml") {
config <- read_yaml(yaml_file_path)[[table_type]]
reactable(
data,
searchable = config$searchable,
filterable = config$filterable,
pagination = config$pagination,
defaultPageSize = config$defaultPageSize
)
}
# Shiny Layer ----
ui <- fluidPage(
reactableOutput("table_a"),
br(),
reactableOutput("table_b")
)
server <- function(input, output, session) {
output$table_a <- renderReactable({
generate_reactable(mtcars, "table_a")
})
output$table_b <- renderReactable({
generate_reactable(mtcars, "table_b")
})
}
shinyApp(ui, server)
table_a:
searchable: false
filterable: false
pagination: true
defaultPageSize: 4
table_b:
searchable: true
filterable: true
pagination: false
defaultPageSize: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment