ThomasSiegmund / D3TableFilter

A table widget based on Max Guglielmi's "HTML Table Filter Generator" and D3.js
Other
65 stars 17 forks source link

use `runApp( list( ui = ui, server = server) )` for examples #4

Closed timelyportfolio closed 9 years ago

timelyportfolio commented 9 years ago

For the examples, especially those in the documentation, using this Shiny format might make it easier for a user to try or explore. Here is an example with the basic app.

# --------------------------------------------------------
# Minimal shiny app demonstrating the D3TableFilter widget

library(shiny)
library(htmlwidgets)
library(D3TableFilter)
data(mtcars)

# ui.R
# --------------------------------------------------------
ui <- shinyUI(fluidPage(
  title = 'Basic usage of D3TableFilter in Shiny',
  fluidRow(
    column(width = 12, d3tfOutput('mtcars'))
  )
))

# server.R
# --------------------------------------------------------
server <- shinyServer(function(input, output, session) {
  output$mtcars <- renderD3tf({

    # Define table properties. See http://tablefilter.free.fr/doc.php
    # for a complete reference
    tableProps <- list(
      btn_reset = TRUE,
      sort = TRUE,
      sort_config = list(
        # alphabetic sorting for the row names column, numeric for all other columns
        sort_types = c("String", rep("Number", ncol(mtcars)))
      )
    );

    d3tf(mtcars,
         tableProps = tableProps,
         showRowNames = TRUE,
         tableStyle = "table table-bordered");
  })
})

runApp(list(ui=ui,server=server))
ThomasSiegmund commented 9 years ago

Done, at least for the first and only complete app in the vignette.

Thanks a lot!