尝试使用 expss 包制作闪亮的表格,但是在下载数据时,HTML 标记也出现在不应该出现的列标题中。
任何人都可以请在这里帮忙。
#install.packages("expss")
library("expss")
library(shiny)
shinyApp(
ui = fluidPage(fluidRow(column(12, dataTableOutput('txt')))),
server = function(input, output) {
table <- reactive({
data(mtcars)
var_text = "vs_sum = vs==0, am_sum = am==1, gear_sum = gear == 4|gear==5, carb_sum = total(carb)"
var_expr = parse(text = sprintf("data.frame(%s)", var_text)) # parse text string to expression
var_list = calc(mtcars, 1*eval(var_expr)) %>% # caclulate data.frame with zero/one columns
prepend_names() %>% # add names as labels
mis_val(0) %>% # we don't need columns with FALSE condition
set_val_lab(c("|" = 1)) # suppress values in table - we don't want to see TRUE/1
mtcars %>%
tab_prepend_values %>%
tab_cols(total(), var_list) %>%
tab_cells(cyl) %>%
tab_stat_cpct() %>%
tab_pivot()
})
output$txt <- renderDataTable({
as.datatable_widget(table(), rownames = F,filter = 'top', extensions = "Buttons",
options = list(
dom = 'Bfrtip',
scrollX = TRUE,
columnDefs = list(list(className = 'dt-center', targets = "_all")),
buttons = list(
'colvis',
list(
extend = 'collection',
buttons = c('csv', 'excel', 'pdf'),
text = 'Download'
)
)
))
}, server = F)
})
下载输出时th { text-align:center; } th{border: 1px solid #DDD与列标题一起出现,我在这里缺少什么。你能建议吗