简体   繁体   English

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

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

I have a dataframe df that I am trying to output as an interactive table in an Xaringan HTML5 presentation .我有一个数据框df ,我试图在Xaringan HTML5 presentation中将其作为交互式表格输出。 The code works fine, it's just that after adding buttons the table no longer completely fits the Chrome browser page as shown in the screen grab below.代码运行良好,只是在添加按钮后,表格不再完全适合 Chrome 浏览器页面,如下面的屏幕截图所示。

在此处输入图像描述

How can I fix this?我怎样才能解决这个问题?

Sample data ( df ):样本数据( 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)) 

Code:代码:

---
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')

```

One option is to add a page length.一种选择是添加页面长度。

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')

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM