我想
formattable
创建一个并排显示表格的报告,- 创建该报告的 HTML、PDF 或图像版本,以及
- 通过电子邮件将其发送给用户,以便他们查看或打印文档。
理想情况下,我将能够生成 HTML 或 PDF 文档,但如果我可以设置分页符,并且绿色检查和红色 X 将在没有 R 的人打印 HTML 或 PDF 时正确打印,我会很高兴文档的版本。
尝试 1。我尝试过的一个选项是 RMarkdown。在这种情况下,我不知道如何并排放置可格式化的表格。这是示例代码:
---
title: "test"
author: "me"
date: "September 21, 2017"
output:
html_document: default
pdf_document: default
---
```{r,echo=F, warning=F}
library(formattable)
library(htmlwidgets)
## Create some data for the tables. I'll want 5 different tables, but for simplicity of this code, let's just repeat the same table 5 times.
d1 = mtcars[5:8, c(1:4,4)]
```
### Three tables I would like to be side-by-side
```{r,echo=F}
# create some formatting for the tables.
hp.formatter = formatter("span", style = x ~ style(color = ifelse(x>=110, "green", ifelse(x<=93, "red", 'white'))), x ~ icontext(ifelse(x>110, "ok", ifelse(x<=93, "remove", ''))))
# Create the tables.
t1 = as.htmlwidget(formattable(d1, list(hp.1=hp.formatter)), width='33%')
t1
t1
t1
```
### Two tables I would like to be side-by-side
```{r,echo=F}
t1
t1
```
尝试 2。或者,我可以使用闪亮的。在这种情况下,我知道如何将formattable
桌子并排放置。但是,我不知道如何将输出下载为 HTML 或 PDF,以便可以通过电子邮件将其发送给用户,以便他们可以打印。这是一些示例代码:
library(shiny)
library(formattable)
library(htmlwidgets)
# Define UI
ui <- fluidPage(
fluidRow(h3(paste0('Three formattable tables side-by-side'))),
fluidRow(column(3, div(tabPanel("Left" , formattableOutput("d1")))), column(1),
column(3, div(tabPanel("Center", formattableOutput("d2")))), column(1),
column(3, div(tabPanel("Right" , formattableOutput("d3")))), column(1)
),
fluidRow(h3(paste0('Two formattable tables side-by-side'))),
fluidRow(column(2),
column(3, div(tabPanel("Left" , formattableOutput("d4")))), column(2),
column(3, div(tabPanel("Right" , formattableOutput("d5")))), column(2)
)
)
server <- function(input, output) {
## Create some data for the table.
## I'll want 5 different tables, but for simplicity, let's just repeat the same data 5 times.
d1 = mtcars[5:8, c(1:4,4)]
## Define some formatting for the formattable tables
hp.formatter = formatter("span", style = x ~ style(color = ifelse(x>=110, "green", ifelse(x<=93, "red", 'white'))), x ~ icontext(ifelse(x>110, "ok", ifelse(x<=93, "remove", ''))))
## Create the table.
t1 = formattable(d1, list(hp.1=hp.formatter))
## Create the outputs. (Repeat same table 5 times)
output$d1=renderFormattable(t1)
output$d2=renderFormattable(t1)
output$d3=renderFormattable(t1)
output$d4=renderFormattable(t1)
output$d5=renderFormattable(t1)
}
# Run the application
shinyApp(ui = ui, server = server)
谢谢你的帮助!