这是我的代码的一部分。
library(shiny)
library(DT)
library(xlsx)
#r input
df <- data.frame(sd = c("A1", "A1", "A1", "A1", "A1", "A1", "A1"),
rsm = c("B", "B", "B", "B", "C", "C", "C"),
asm = c("D", "D", "E", "E", "F", "G", "H"),
sr = c("I", "J", "K", "L", "M", "N", "O"),
revenue _target = c(100, 300, 200, 300, 120, 160, 100),
revenue_achive = c(80, 30, 150, 450, 20, 80, 12),
revenue_perachive = c(80, 10, 75, 150, 25, 50, 12),
quantites_target = c(30, 40, 60, 20, 15, 42, 30),
quantities_achive = c(15, 25, 30, 42, 10, 10, 12),
quantities_perachive = c(50, 62.5, 50, 210, 66.67, 23.81, 40),
day = c(10, 10, 10, 12, 12, 12, 12),
month = c(2017, 2017, 2017, 2017, 2017, 2017, 2017),
stringsAsFactors = FALSE)
)
#r formatting table
sketch <- htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, ''),
th(rowspan = 2, 'sd'),
th(rowspan = 2, 'rsm'),
th(rowspan = 2, 'asm'),
th(rowspan = 2, 'sr'),
th(colspan = 2, 'Revenue'),
th(colspan = 2, 'Quantites'),
th(rowspan = 2, 'day'),
th(rowspan = 2, 'month')
),
tr(
lapply(rep(c('target', 'achive', 'perachive'), 2), th)
)
)
))
out_table <- reactive({
out <- df
out
})
output$out_tbl <- DT::renderDataTable (
{out_table()},
rownames = FALSE,
container = sketch
)
fluiRow(
column(
width = 12,
dataTableOutput("out_tbl")
))
重新启动后,在DT::renderDataTable
中,我添加了一个选项:container = sketch
。我有两个误解:
第一个,在htmltools::withTags
中,如果列合并的单元格数相同,我会这样做。你看到样本,它是3列:“目标”,“achive”和“perachive”。名为“month”和“year”的列,我无法合并。
第二,当我下载excel时,格式化表格丢失了。我不明白。
这是我的输出图片。
我怎么能这样做,比如输出图片?