Let's say I have an Rmarkdown document. In that document, I create an data frame with two columns, and each of them is quite long. Also I have the "paged" output setting.
---
title: "Long Tables"
output:
html_document:
toc: true
toc_depth: 3
df_print: paged
---
```{r}
alphabet = paste(LETTERS, letters, collapse = "", sep = "")
data.frame(
a = rep(alphabet, 10),
b = rep(alphabet, 10)
)
When I knit this to HTML, it appears like this:

It is important that I can get both columns to fit on screen without the user having to click through to each column. Ideally there would be an rmarkdown setting to solve this. If not, is there a way to actually truncate the columns behind the scenes, but without actually showing the user the code that is doing the truncation? Because this will complicate the example that I am demonstrating in the document.
Try this solution:
Your data:
```{r, echo=FALSE}
alphabet = paste(LETTERS, letters, collapse = "", sep = "")
df <- data.frame(
a = rep(alphabet, 10),
b = rep(alphabet, 10)
)
```
Your table:
```{r, echo=FALSE, warning=FALSE}
library(DT)
datatable(df, extensions = 'FixedColumns')
```
P.S. How to customize your table further - you can find a lot of interesting info there

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With