我有一个R闪亮的应用程序,下面我可以在浏览器中显示uiOutput,现在我想添加downloadHandler来下载uiOutput to 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()```感谢您的时间和帮助。
发布于 2021-03-27 18:13:59
我终于找到了下面这个问题的解决方案,如果你找到了更好的方法,请随时添加答案或评论。谢谢
#Inside download_content function
content <- function(file) {
out <- rmarkdown::render('RMarkdownFile.rmd', output_format = 'html_document')
}
file.rename(out, file)https://stackoverflow.com/questions/66778268
复制相似问题