带按钮的 R DT table 不适合 Xaringan HTML5 演示文稿中的页面

R DT table with buttons does not fit page in Xaringan HTML5 presentation

我有一个数据框 df,我正试图将其作为交互式 table 在 Xaringan HTML5 presentation 中输出。代码工作正常,只是在添加按钮后 table 不再完全适合 Chrome 浏览器页面,如下面的屏幕截图所示。

我该如何解决这个问题?

示例数据(df):

structure(list(City = c("HOLLYWOOD", "PLANTATION", "Davie", "HOLLYWOOD", 
"PLANTATION", "HOLLYWOOD", "PLANTATION", "Davie", "HOLLYWOOD", 
"PLANTATION"), Zipcode = c("33024", "33317", "33314", "33024", 
"33317", "33024", "33317", "33314", "33024", 
"33317"), Date = structure(c(18996, 18633, 19011, 19012, 19016, 18996, 18633, 19011, 19012, 19016
), class = "Date"), Year = c(2022, 2021, 2022, 2022, 2022, 2022, 2021, 2022, 2022, 2022), Month = c(1, 
1, 1, 1, 1, 1, 
1, 1, 1, 1), Day = c(4, 6, 19, 20, 24, 4, 6, 19, 20, 24), SR = c("SR-22-001", "SR-22-002", 
"SR-22-003", "SR-22-004", "SR-22-006", "SR-22-001", "SR-22-002", 
"SR-22-003", "SR-22-004", "SR-22-006"), Permit = c("06-SE-2433290", 
"06-SE-2444371", "06-SM-2448351", "06-SM-2448625", NA, "06-SE-2433290", 
"06-SE-2444371", "06-SM-2448351", "06-SM-2448625", NA), `Owner/Agent` = c("Pardo, G A & Elaine Nu-Black Septic Co", 
"Alshine Mondesir A Tip Top Septic", "Charlotte Ingmire Mr. C's Pumbling & Septic Inc.", 
"SRP Sub LLC Statewide Septic Cont Inc", "John Nelson Mr. C's Pumbling & Septic Inc.", "Pardo, G A & Elaine Nu-Black Septic Co", 
"Alshine Mondesir A Tip Top Septic", "Charlotte Ingmire Mr. C's Pumbling & Septic Inc.", 
"SRP Sub LLC Statewide Septic Cont Inc", "John Nelson Mr. C's Pumbling & Septic Inc."
), Address = c("1111 Harding St Hollywood, FL 33024", "5555 W Broward Blvd Plantation, 33317", 
"1111 SW 74 Ave Davie, 33314", "2222 Thomas Street Hollywood, FL 33024", 
"333 Bryan Blvd Plantation, 33317", "12345 Harding St Hollywood, FL 33024", "34556 W Broward Blvd Plantation, 33317", 
"55656 SW 74 Ave Davie, 33314", "3333 Thomas Street Hollywood, FL 33024", 
"316 Bryan Blvd Plantation, 33317")), sfc_columns = c("x", "y"
), class = "data.frame", row.names = c(NA, -5L)) 

代码:

---
title: "Ed Edd n Eddy
subtitle: ""
author: "Ed"
institute: "Gravy"
date: "`r format(Sys.Date(),'%e de %B, %Y')`"
output:
  xaringan::moon_reader:
    css: xaringan-themer.css
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
editor_options: 
  chunk_output_type: console
---

<style>
div.remark-slide-content {
  padding: 1em; /*default is 1em 4em*/
}
.dataTables_wrapper {
  font-size: .5em;
}
</style>

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
library(knitr)
library(tidyverse)
library(sf)
library(DT)
library(xaringanthemer)
```
---
# Interactive Table
```{r, Data Table}
datatable(df,
          extensions = 'Buttons', options = list(
    dom = 'Bfrtip',
    buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
  ))  %>%
  formatStyle(names(df),
                              background = 'lightblue', angle = -90,
                              backgroundSize = '98% 88%',
                              backgroundRepeat = 'no-repeat',
                              backgroundPosition = 'center')

```

一个选项是添加页面长度。

datatable(df,
          extensions = 'Buttons', options = list(
            pageLength = 5,    
            dom = 'Bfrtip',
            buttons = c('copy', 'csv', 'excel', 'pdf', 'print'))) %>%
  formatStyle(names(df),
              background = 'lightblue', angle = -90,
              backgroundSize = '98% 88%',
              backgroundRepeat = 'no-repeat',
              backgroundPosition = 'center')