Last data update: 2014.03.03

R: Register a data object in a shiny session for DataTables
dataTableAjaxR Documentation

Register a data object in a shiny session for DataTables

Description

This function stores a data object in a shiny session and returns a URL that returns JSON data based on DataTables Ajax requests. The URL can be used as the url option inside the ajax option of the table. It is basically an implementation of server-side processing of DataTables in R. Filtering, sorting, and pagination are processed through R instead of JavaScript (client-side processing).

Usage

dataTableAjax(session, data, rownames, filter = dataTablesFilter)

Arguments

session

the session object in the shiny server function (function(input, output, session))

data

a data object (will be coerced to a data frame internally)

rownames

see datatable(); it must be consistent with what you use in datatable(), e.g. if the widget is generated by datatable(rownames = FALSE), you must also use dataTableAjax(rownames = FALSE) here

filter

(for expert use only) a function with two arguments data and params (Ajax parameters, a list of the form list(search = list(value = 'FOO', regex = 'false'), length = 10, ...)) that return the filtered table result according to the DataTables Ajax request

Details

Normally you should not need to call this function directly. It is called internally when a table widget is rendered in a Shiny app to configure the table option ajax automatically. If you are familiar with DataTables' server-side processing, and want to use a custom filter function, you may call this function to get an Ajax URL.

Value

A character string (an Ajax URL that can be queried by DataTables).

References

http://rstudio.github.io/DT/server.html

Examples

DTApp = function(data, ..., options = list()) {
  library(shiny)
  library(DT)
  shinyApp(
    ui = fluidPage(
      title = 'Server-side processing of DataTables',
      fluidRow(
        DT::dataTableOutput('tbl')
      )
    ),
    server = function(input, output, session) {
      options$serverSide = TRUE
      options$ajax = list(url = dataTableAjax(session, data))
      # create a widget using an Ajax URL created above
      widget = datatable(data, ..., options = options)
      output$tbl = DT::renderDataTable(widget)
    }
  )
}

if (interactive()) DTApp(iris)
if (interactive()) DTApp(iris, filter = 'top')

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DT)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DT/dataTableAjax.Rd_%03d_medium.png", width=480, height=480)
> ### Name: dataTableAjax
> ### Title: Register a data object in a shiny session for DataTables
> ### Aliases: dataTableAjax
> 
> ### ** Examples
> 
> DTApp = function(data, ..., options = list()) {
+   library(shiny)
+   library(DT)
+   shinyApp(
+     ui = fluidPage(
+       title = 'Server-side processing of DataTables',
+       fluidRow(
+         DT::dataTableOutput('tbl')
+       )
+     ),
+     server = function(input, output, session) {
+       options$serverSide = TRUE
+       options$ajax = list(url = dataTableAjax(session, data))
+       # create a widget using an Ajax URL created above
+       widget = datatable(data, ..., options = options)
+       output$tbl = DT::renderDataTable(widget)
+     }
+   )
+ }
> 
> #if (interactive()) DTApp(iris)
> #if (interactive()) DTApp(iris, filter = 'top')
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>