r - 保存和删除文件
问题描述
我希望在闪亮的应用程序中具有在用户在文本区域中输入输入后下载 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)
解决方案
如果可以选择创建临时文件,我们创建一个文件,将输入写入其中,进行转换,然后删除该文件
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)
推荐阅读
- android - 在 android 应用程序 kotlin 上对图像进行精明的边缘检测
- css - 动画迭代计数无限在 Safari 上不起作用
- c++ - 如何从网站获取数据并将其传输到数据库?
- r - R - 绘制两个时间序列只显示第一个
- python - 设置 DEBUG 环境变量时,如何禁用 numba 调试日志记录?
- javascript - 如何使用变量加载 json 值?[JS]
- javascript - `npm list` 错误:`mainprocess 退出代码:1`
- c++ - 使用带有 ref 参数的成员函数创建线程时出现编译错误
- python - 'function' 对象没有属性 'load_data'
- vba - 如何更改 MailItem 的 HTML 正文中的字符集?