【问题标题】:Save and remove file保存和删除文件
【发布时间】:2021-03-13 21:17:22
【问题描述】:

我希望在闪亮的应用程序中具有在用户在文本区域输入输入后下载 word doc 的功能。用户将以 html 形式提供输入。下载按钮应该会生成 docx 文件。

library(shiny)

ui <- fluidPage(
  fluidRow(
    column(6, offset = 3,
           hr(),
           h2('Editor:'),
           textInput('editor1', 'MY TEXT',
                   HTML('<b>Sam</b> <i>Dave</i>'), 
                   ),
           hr(),
           h2('Editor Content:'),
           htmlOutput('editor1_content')
    )
  )
)

server <- function(input, output, session) { 
  output$editor1_content <- renderUI({HTML(enc2utf8(input$editor1))})
}

shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny r-markdown


    【解决方案1】:

    如果可以选择创建临时文件,我们会创建一个文件,将输入写入其中,进行转换,然后删除该文件

    file1 <- file.path(tempdir(), "test.html")
    writeLines(text = "<b>Sam</b> <i>Dave</i>", con = file1)
    rmarkdown::pandoc_convert(file1, to = "docx", output = "word.docx")
    file.remove(file1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      相关资源
      最近更新 更多