【问题标题】:RShiny - When printing the table from renderDT it prints the HTML code for the title instead of just the titleR Shiny - 从 renderDT 打印表格时,它会打印标题的 HTML 代码,而不仅仅是标题
【发布时间】: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


    【解决方案1】:

    你可以这样设置你想要的标题:

    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")
          )
        )
      )
    })
    

    【讨论】:

      猜你喜欢
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多