Formatting a Fancy DataTable in R Shiny: A Step-by-Step Guide with DT
Formatting a Fancy DataTable in R Shiny: A Step-by-Step Guide with DT
Creating a "fancy" DataTable in R Shiny using the DT package hinges on leveraging specific arguments to enhance both functionality and aesthetics. In the datatable() function, the extensions = c("FixedColumns") argument paired with options = list(fixedColumns = list(leftColumns = 1)) pins the label column, ensuring readability while scrolling horizontally with scrollX = TRUE. The options list further refines the table: order = list() and columnDefs = list(list(targets = "_all", orderable = FALSE)) disable sorting for a clean, controlled presentation, while pageLength = nrow(data) displays all rows without pagination, and dom = 't' removes extraneous controls for a minimalist look. The rownames = FALSE argument hides row indices, streamlining the design.
Styling elevates the visual appeal: formatStyle(columns = names(data), color = 'black', fontSize = '15px', backgroundColor = '#f2ede8') sets a consistent beige backdrop and readable text across all cells. Targeted styling with formatStyle('label', backgroundColor = "#ecfafb", fontWeight = 'bold') highlights the label column in light cyan, while formatStyle('Overall', backgroundColor = "#feca90", fontWeight = 'bold') emphasizes the Overall column in soft orange. These arguments combine to create a polished, user-friendly DataTable that balances functionality with a professional, visually engaging design.