【发布时间】:2020-10-28 23:27:45
【问题描述】:
在我闪亮的应用程序中,我希望能够从表格中创建 excel 或 pdf。我正在使用 renderDT 创建表格,并使用该函数中的选项内的按钮来拥有该功能。在闪亮的应用程序上运行后,单击 pdf 按钮时,表格打印良好,但其顶部的标题显示标题的 HTML 代码,而不是标题本身。还有其他方法可以创建标题,但我以特定的方式来创建标题,因此我可以在标题中添加徽标。
这里是一些示例代码:
library(shiny)
library(shinydashboard)
library(data.table)
library(DT)
library(tableHTML)
# Data
Op_dataGen <- data.table(Var1 = 1:100,
Var2 = sample(letters, 100, replace = TRUE))
ui <- fluidPage(
tags$style(".main-sidebar {padding-top: 74px}"),
tags$head(tags$style(
HTML('
.skin-blue .main-header .logo {background-color:#1F3758; font-size:auto; display:contents;
font-weight:bold; }
.skin-blue .main-header .logo b {color:#fff; font-size:auto; font-weight:bold;}
'
))),
dashboardPage(
# a) header
dashboardHeader(
title = span(img(src="logo.png", width = 250), tags$b('Organization Title')),
tags$li(tags$style(".main-header {max-height: 74px}"),
tags$style(".main-header .logo {height: 74px, width: 90px}"),
class = "dropdown")
),
dashboardSidebar(width=250,
sidebarMenu(id = 'sidebar',
#Tabs#
menuItem('View Table', tabName = 'table'))
),
# c) body
dashboardBody(
fluidRow(
tabItems(
tabItem(tabName = 'table',
box(width = 12,
title = 'Total NumberTable',
DTOutput('TableG'))
))))
)
)
server <- shinyServer(function(input, output) {
TableG <- copy(Op_dataGen)
output$TableG <- renderDT({
TableG
},
rownames = FALSE,
extensions = 'Buttons',
options = list(
pageLength = 100,
scrollY = '360px',
scrollX = TRUE,
dom = 'Bfrtip',
buttons = c('copy', 'excel', 'pdf')
)
)
})
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r shiny shinydashboard dt