Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Forked from trestletech/server.R
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jcheng5/9494813 to your computer and use it in GitHub Desktop.
Save jcheng5/9494813 to your computer and use it in GitHub Desktop.
Title: Basic DataTable
Author: Jeff Allen <jeff@rstudio.com>
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: mtcars selectinput datatables
Type: Shiny
library(shiny)
# Load the ggplot2 package which provides
# the 'mpg' dataset.
library(ggplot2)
# Define a server for the Shiny app
shinyServer(function(input, output) {
# Filter data based on selections
output$table <- renderDataTable({
data <- mpg
if (input$man != "All"){
data <- data[data$manufacturer == input$man,]
}
if (input$cyl != "All"){
data <- data[data$cyl == input$cyl,]
}
if (input$trans != "All"){
data <- data[data$trans == input$trans,]
}
data
})
})
library(shiny)
# Load the ggplot2 package which provides
# the 'mpg' dataset.
library(ggplot2)
# Define the overall UI
shinyUI(
fluidPage(
titlePanel("Basic DataTable"),
# Create a new Row in the UI for selectInputs
fluidRow(
column(4,
selectInput("man",
"Manufacturer:",
c("All",
unique(as.character(mpg$manufacturer))))
),
column(4,
selectInput("trans",
"Transmission:",
c("All",
unique(as.character(mpg$trans))))
),
column(4,
selectInput("cyl",
"Cylinders:",
c("All",
unique(as.character(mpg$cyl))))
)
),
# Create a new row for the table.
fluidRow(
dataTableOutput(outputId="table")
)
)
)
@arunsoni
Copy link

I have two questions on this app:

  • where is the code that defines the number of records per page that the user can control
  • where is the code for the search bar that allows the user to filter the selected display

Thank you

@ctbrown
Copy link

ctbrown commented May 29, 2014

@arunsoni: Those are options to the DataTables js library (https://datatables.net/) that can be passed using options argument to renderDataTable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment