Interactive tables

In the preceding example application, we saw how to make our plot interactive. Now it's time to make tables interactive. Interactive plots mean we can have freedom in selecting rows/columns/cells and shorting columns.

DT is a package with DT library that helps us to make tables more interactive. Let's see a small client-side example of Data Tables with Shiny:

library(shiny) 
library(DT) 
shinyApp( 
  ui = fluidPage(DTOutput('tbl')), 
  server = function(input, output) { 
    output$tbl = renderDT( 
      iris, options = list(lengthChange = FALSE) 
    ) 
}) 

In the preceding code, DTOutput() is for outputting the table on UI, and on the server side we have used renderDT() to send the data into the UI from the iris dataset. The output can be seen here:

We can see in the preceding screenshot that we can select rows using a mouse pointer. In this way, interactive functionality can be added to tables.

DT supports both server-side and client-side processing; the default is server-side, but client-side can be set by calling DT::renderDT() with a server = FALSE argument. If the dataset is relatively small, use server = FALSE, otherwise it will be too slow to render the table in the web browser, and the table will not be very responsive, for a large data set. Example code:

DT::renderDataTable(iris, server = FALSE) 
For more details https://rstudio.github.io/DT/ link can be followed. 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset