RShiny:在Shiny中创建.docx文件时遇到问题

时间:2019-03-09 23:28:12

标签: r shiny

我正在尝试使用officer包将数据存储在闪亮的应用程序中为word文件。奇怪的是,它可以在IDE中工作,但不能在应用程序中工作。此外,简单地说,我没有收到任何错误。

这是在IDE中发生的事情:

library(magrittr)
library(officer)

x<-'square'

doc <- read_docx()

doc <- doc %>%
      body_add_par(paste('My favorite shape is',input$id), style = "Normal") %>%
      body_add_table(iris,style = "table_template")

    print(doc,target = "doc1.docx")
  

这可以正常运行,创建Word(.docx)文件,如下所示:

docx

但是,当尝试将其包含在Shiny中时,什么也没发生:

library(shiny)
library(magrittr)
library(officer)


ui <- fluidPage(
  selectizeInput('id','Choose shape:',
                 choices = c('Triangle','Circle','Square')),

  actionButton('submit','Submit Form', icon = icon('table'))
)

server <- function(input, output) {

  WriteWord<-function() {

    doc <- read_docx()

    doc <- doc %>%
      body_add_par(paste('My favorite shape is',input$id), style = "Normal") %>%
      body_add_table(iris,style = "table_template")
    print(doc,target = "doc1.docx")
  }

  observeEvent(input$submit, {
    WriteWord()
  })


}

shinyApp(ui = ui, server = server)

没有错误,没有任何反应。我单击操作按钮,但未创建文件。奇怪的。

0 个答案:

没有答案