#r #shiny #shinyapps
Вопрос:
У меня есть приложение R Shiny, ниже которого я могу отображать вывод UI в браузере, теперь я хочу добавить загрузчик для загрузки содержимого вывода UI в 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()```
Спасибо вам за ваше время и помощь.
Ответ №1:
Я, наконец, нашел решение этой проблемы ниже, если вы найдете что-то лучшее, пожалуйста, не стесняйтесь добавлять ответ или комментарий. Спасибо
#Inside download_content function
content <- function(file) {
out <- rmarkdown::render('RMarkdownFile.rmd', output_format = 'html_document')
}
file.rename(out, file)