get_dt_rows: Maps the 'lengthMenu'selected value property of...

View source: R/get_dt_rows.R

get_dt_rowsR Documentation

Maps the lengthMenuselected value property of DT::datatable to a Shiny variable.

Description

[Stable]

Usage

get_dt_rows(dt_name, dt_rows)

Arguments

dt_name

ns() of inputId of the DT::datatable

dt_rows

ns() of inputId of the variable that holds the current selected value of lengthMenu

Value

(shiny::tagList) A ⁠shiny tagList⁠.

Examples

library(shiny)
ui <- function(id) {
  ns <- NS(id)
  tagList(
    DT::DTOutput(ns("data_table")),
    get_dt_rows(ns("data_table"), ns("dt_rows"))
  )
}

# use the input$dt_rows in the Shiny Server function
server <- function(id) {
  moduleServer(id, function(input, output, session) {
    output$data_table <- DT::renderDataTable(
      {
        iris
      },
      options = list(pageLength = input$dt_rows)
    )
  })
}

if (interactive()) {
  shinyApp(
    ui = ui("my_table_module"),
    server = function(input, output, session) server("my_table_module")
  )
}

teal.widgets documentation built on May 29, 2024, 2:41 a.m.