R Shiny - 从 renderDT 打印 table 时,它会打印标题的 HTML 代码,而不仅仅是标题
RShiny - When printing the table from renderDT it prints the HTML code for the title instead of just the title
在我闪亮的应用程序中,我希望能够从 table 创建 excel 或 pdf。我正在使用 renderDT 创建 table,并在该函数的选项内创建按钮以具有该功能。在闪亮的应用程序上,一旦它是 运行,当单击 pdf 按钮时,table 打印良好,但它顶部的标题显示标题的 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)
你可以这样设置你想要的标题:
output$TableG <- renderDT({
datatable(
TableG,
rownames = FALSE,
extensions = "Buttons",
options = list(
pageLength = 100,
scrollY = '360px',
scrollX = TRUE,
dom = 'Bfrtip',
buttons = list(
list(extend = "copy", title = "TheTitleYouWant"),
list(extend = "excel", title = "TheTitleYouWant"),
list(extend = "pdf", title = "TheTitleYouWant")
)
)
)
})
在我闪亮的应用程序中,我希望能够从 table 创建 excel 或 pdf。我正在使用 renderDT 创建 table,并在该函数的选项内创建按钮以具有该功能。在闪亮的应用程序上,一旦它是 运行,当单击 pdf 按钮时,table 打印良好,但它顶部的标题显示标题的 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)
你可以这样设置你想要的标题:
output$TableG <- renderDT({
datatable(
TableG,
rownames = FALSE,
extensions = "Buttons",
options = list(
pageLength = 100,
scrollY = '360px',
scrollX = TRUE,
dom = 'Bfrtip',
buttons = list(
list(extend = "copy", title = "TheTitleYouWant"),
list(extend = "excel", title = "TheTitleYouWant"),
list(extend = "pdf", title = "TheTitleYouWant")
)
)
)
})