r - 如何在 R 中将 uiOutput 下载为 HTML 文档
问题描述
我有 R Shiny 应用程序,我可以在浏览器中显示 uiOutput,现在我想添加 downloadHandler 以将 uiOutput 的内容下载到 HTML 文档。
下面是我的代码
library(shiny)
library(knitr)
library(rmarkdown)
ui <- shinyUI(
fluidPage(
uiOutput('markdown'),
downloadButton('Download_Output')
)
)
server <- function(input, output) {
output$markdown <- renderUI({
HTML(markdown::markdownToHTML(knit('RMarkdownFile.rmd', quiet = TRUE)))
})
output$Download_Output <- downloadHandler(
filename <- function() {
paste("output_", Sys.Date(), ".html", sep = "")
},
content <-
function(file) {
#render("RMarkdownFile.rmd",html_document())
}
)
}
shinyApp(ui, server)
以下是示例 R Markdown 文件。
``{python py-code, echo=FALSE, exercise=TRUE}
import matplotlib.pyplot as plt
left = [1, 2, 3, 4, 5]
height = [10, 24, 36, 40, 5]
tick_label = ['one', 'two', 'three', 'four', 'five']
plt.bar(left, height, tick_label = tick_label, width = 0.8, color = ['red', 'green'])
# naming the x-axis
plt.xlabel('x - axis')
# naming the y-axis
plt.ylabel('y - axis')
# plot title
plt.title('My bar chart!')
# function to show the plot
plt.show()```
感谢您的时间和帮助。
解决方案
我终于找到了解决此问题的以下方法,如果您发现更好的方法,请随时添加答案或评论。谢谢
#Inside download_content function
content <- function(file) {
out <- rmarkdown::render('RMarkdownFile.rmd', output_format = 'html_document')
}
file.rename(out, file)
推荐阅读
- wordpress - wordpress - 在whatsapp链接中共享私人内容未正确显示
- html - 如何让语义 UI 段正确适应页面宽度
- php - 在 laravel 控制器中进行 Foreach,但只得到单个数据
- machine-learning - 机器学习模型的行业生产参数
- python - Keras model & Tensorflow Estimator - 模型响应处理
- .net - pdf格式在itext7中为空
- c# - 如何通过反射从不同的程序集中调用具有内部委托参数的内部方法?
- mongodb - 如何获取 perl MongoDB 管理模块
- python - 在 Python 中拆分列表并将其插入 Excel
- c++ - 使用示例构建 websocketpp 时出现链接错误