--- 
title: "[R Markdown] DT::datatable tutorial" 
author: "by SK C&C 이다경 선임 -`r format(Sys.Date())`"
output:  
  rmdformats::readthedown: 
    code_folding: show 
    number_sections: TRUE
--- 


<style> 
#TOC { 
  top: 1%; 
  opacity: 0.5; 
} 
#TOC:hover { 
  opacity: 1; 
} 
</style>

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE, warning=FALSE, message=FALSE, results = 'asis')
options(warn = F)

library(DT)
```

# 기본

```{r}
datatable(iris) 
```

<br>
<hr>
<br>

# cation :: 제목 추가

```{r}
datatable(iris,
          caption = "IRIS DATA SET") 
```

<br>
<hr>
<br>

# rownames :: ROW INDEX 삭제

```{r}
datatable(iris,
          caption = "IRIS DATA SET",
          rownames = F) 
```

<br>
<hr>
<br>

# colnames :: Column 명 변경

```{r}
datatable(iris,
          caption = "IRIS DATA SET",
          rownames = F,
          colnames = c("Col1"="Sepal.Length")) 
```

<br>
<hr>
<br>

# filter

```{r}
datatable(iris,
          caption = "IRIS DATA SET",
          rownames = F,
          colnames = c("Col1"="Sepal.Length"),
          filter = "bottom") 
```

<br>
<hr>
<br>

# width, height

```{r}
datatable(iris,
          caption = "IRIS DATA SET",
          rownames = F,
          colnames = c("Col1"="Sepal.Length"),
          filter = "bottom",
          width = 500, height = 500) 
```

<br>
<hr>
<br>

# editable

```{r}
datatable(iris,
          caption = "IRIS DATA SET",
          rownames = F,
          colnames = c("Col1"="Sepal.Length"),
          filter = "bottom",
          editable = T) 
```

<br>
<hr>
<br>

# extensions + options :: datatable 파일 저장하기 {.tabset}

## no scroll
```{r}
datatable(dplyr::bind_cols(iris,iris),
          caption = "IRIS DATA SET",
          rownames = F,
          filter = "bottom",
          editable = T,
          extensions = "Buttons",
          options = list(dom ='Bfrtip', 
                         buttons =c(I('colvis'),'copy','csv', 'excel','print','pdf'),
                         pageLength = 10))
```


<br>
<hr>
<br>

## scroll
```{r}
datatable(dplyr::bind_cols(iris,iris),
          caption = "IRIS DATA SET",
          rownames = F,
          # colnames = c("Col1"="Sepal.Length"),
          filter = "bottom",
          editable = T,
          extensions = "Buttons",
          options = list(dom ='Bfrtip', 
                         buttons =c(I('colvis'),'copy','csv', 'excel','print','pdf'),
                         pageLength = 10,
                         scrollX = T))
```

<br>
<hr>
<br>

# class {.tabset}

```{r}
class <- c("display","cell-border","compact","hover","nowrap","order-column","row-border","stripe")
for(i in class){
  cat("\n\n##",i,"\n\n")
  
  print(htmltools::tagList(datatable(dplyr::bind_cols(iris,iris),
          caption = "IRIS DATA SET",
          rownames = F,
          filter = "bottom",
          editable = T,
          extensions = "Buttons",
          width = 800,
          options = list(dom ='Bfrtip', 
                         buttons =c(I('colvis'),'copy','csv', 'excel','print','pdf'),
                         pageLength = 10,
                         scrollX = T),
          class = i)))
  cat("\n\n<br><hr><br>\n\n")
  
}

```

<br>
<hr>
<br>


