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

发布于 2025-02-04 05:36:50 字数 3303 浏览 4 评论 0原文

我有一个dataframe df,我试图在Xaringan HTML5呈现中作为交互式表输出。该代码正常工作,只是在添加按钮后,该表不再完全适合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')

```

I have a dataframe df that I am trying to output as an interactive table in an 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.

enter image description here

How can I fix this?

Sample data (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')

```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心清如水 2025-02-11 05:36:50

一种选择是添加页面长度。

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

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

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文