如何解决“在flextable错误:无效col_keys,flextable只支持语法名称”中downloadHanler

问题描述 投票:0回答:1

我有闪亮的服务器如下:

shinyServer(function(input, output){

  t1 <- reactive({
    tab1 <- data.table("Fields"=c("Contact Person",
                                        "Cost Center:",
                                        "Department:",
                                        "Date:"

                       "Detailed information" = c(input$`Contact Person`,
                                                  input$`Cost`,
                                                  input$`Department`,
                                                  format(input$`Date`[1])


    tab1

  })
        output$tbl1 <- renderTable({
    if (is.null(t1()))
      return(NULL)
    t1()
  })

输出$下载1 = downloadHandler(

filename = function(){
  paste("InternalRequest_",Sys.Date(),".docx", sep ="")

},
content = function(file){

  ft <- flextable(t1())
  ft <- theme_vanilla(ft)

  doc = read_docx(path="B:\\Desktop\\Internal Request.docx")
  doc<-doc%>%cursor_bookmark("DATA")
  doc<-body_add_flextable(doc, ft, pos = "on")

  print(doc, file = file)
})
 })

下载不工作,我收到消息“警告:错误flextable:无效col_keys,flextable只支持语法名称”。谁能帮我解决问题?谢谢!

r shiny shiny-server shinydashboard
1个回答
1
投票

我给我的建议,根据我的理解。是通过你的反应数据集到flextable之前,我们应该保持适宜的colnames。例如,在你的情况反应数据集的colnames包含空间(详细信息)。为了使正确的colnames,我使用功能clean_names()从看门包。使用下面的代码

 library(janitor)
  t1() %>% 
   clean_names() %>%
   flextable() %>% 
   theme_vanilla() %>%
   set_header_labels(fields = "Fields",detailed_information = "Detailed information") -> ft

代替

ft <- flextable(t1())
ft <- theme_vanilla(ft)

您downloadHandler内

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.