Data index
Use R Quarto Markdown files to render an interactive table
Quarto
R
Markdown
YAML
Template 1 - Read Excel and Render Interactive
You can copy the following content into an empty .qmd file, fill in your file paths and names when necessary and click ‘render’ in R studio (latest version recommended for better Quarto support). This will automatically save it as an .HTML file in the same folder as the .qmd file. The libraries loaded with library()
are additional R packages that first need to be installed with install.packages()
.
---
#title: "Page-title"
subtitle: "Page-subtitle"
author: "author-name"
affiliation: "affiliation-name"
date: last-modified
format: html
---
# Read metadata table
```{r readfiles}
#| code-fold: true
library(openxlsx)
# Manual inputs
input_table_1 = 'table_filename.xlsx' # specify fullpath if not in current dir
sheet_name = 'sheetname' # insert name of sheet in table
miss_val_spec = c("","N/A") # labels used to specify missing value
# read data
tbl <- openxlsx::read.xlsx(xlsxFile = input_table_1,
sheet = sheet_name,
na.strings = c("","N/A"))
```
> This table has `r nrow(tbl)` rows and `r ncol(tbl)` columns
# Render interactive table
```{r , renderTable}
library(DT)
datatable(
tbl,
filter = "top",
escape = FALSE,
rownames = FALSE,
width = "100%",
class = 'compact cell-border hover',
extensions = c('Buttons', 'Select','ColReorder', 'Scroller', 'KeyTable'),
selection = 'none',
options = list(
pageLength = 10,
dom = 'Bfrtip',
#buttons = c('colvis','selectAll', 'selectNone', 'copy', 'csv', 'pdf'),
buttons = list(list(extend = "colvis", text = "select Columns"),'selectAll', 'selectNone', 'copy', 'csv', 'pdf'),
select = list(style = 'os', items = 'row'),
scrollX = TRUE,
scrollCollapse = FALSE,
autoWidth = TRUE,
colReorder = TRUE,
columnDefs = list(
list(
keys = TRUE,
search = list(regex = TRUE),
targets=0
)
)
)
)
```