dataTable

dataTable
dataTable 출력은 http://datatables.net에서 제공하는 자바스크립트를 사용한다.
이는 ui.R, server.R을 굳이 나누지 않고 사용할 수 있지만, 코드의 관리와 시안성을 위해 나누는 것이 좋다.
checkboxGroupInput(inputId, label, choices, selected=NULL)
helpText(...)
tabsetPanel(..., id=NULL, selected=NULL)
tabPanel(title, ..., value=NULL)
renderDataTable(expr, options=NULL, searchDelay=500, env=parent.frame(), quoted=FALSE)
data_table.R(dataTable)
library(shiny)
runApp(list(
ui=basicPage(
h2('The mtcars data'),
dataTableOutput('mytable')
),
server=function(input, output){
output$mytable=renderDataTable({
mtcars
})
}
))
체크박스를 추가한 datatable
ui.R(dataTable)
library(shiny)
library(ggplot2)
shinyUI(pageWithSidebar(
headerPanel("examples of DataTables"),
sidebarPanel(
checkboxGroupInput("show_vars", "Columns in diamonds to show: ", names(diamonds), selected=names(diamonds)),
helpText('For the diamonds data, we can select variabels to show in the table; for the mtcars example, we use bSortClasses=TRUE so that sorted columns are colored since they have special CSS classes attached; for the iris data, we customize the length menu so we can displaye 5 rows per page.')
# helpText text
),
mainPanel(
tabsetPanel(
tabPanel('diamonds', dataTableOutput("mytable1")),
tabPanel('mtcars', dataTableOutput("mytable2")),
tabPanel('iris', dataTableOutput("mytable3"))
)
)
))
server.R(dataTable)
library(shiny)
shinyServer(function(input, output){
output$mytable1=renderDataTable({
require(ggplot2)
diamonds[, input$show_vars, drop=FALSE]
})
output$mytable2=renderDataTable({
mtcars
}, options=list(bSortClasses=TRUE)) # sorted ,
output$mytable3=renderDataTable({
iris
}, options=list(aLengthMenu=c(5, 30, 50), iDisplayLength=5))
# aLengthMenu( )
# iDisplayLength( )
})