尝试在闪亮的应用程序中使用RMarkdown下载PDF
我正在尝试从一个闪亮的应用程序生成PDF格式的报告。我有两个问题:尝试在闪亮的应用程序中使用RMarkdown下载PDF,r,shiny,r-markdown,shinydashboard,ggplotly,R,Shiny,R Markdown,Shinydashboard,Ggplotly,我正在尝试从一个闪亮的应用程序生成PDF格式的报告。我有两个问题: 报告不以PDF格式下载,仅以HTML格式下载。如何在PDF上下载 未显示渲染内容的报告(本例中为ggplotly图像), 只是显示文本。如何使PDF包含Shining应用程序中显示的图像 我做错了什么?有什么想法吗 library(ggplot2) library(plotly) library(gapminder) library(shiny) library(shinydashboard) library(rmarkdown
library(ggplot2)
library(plotly)
library(gapminder)
library(shiny)
library(shinydashboard)
library(rmarkdown)
bodyplotly <- dashboardBody(
fluidRow(
column(12,
box(width=10,
title = "ggplotly",
plotlyOutput("selected_plot"),
box(
width = 2, height=250,
sliderInput("year", label=("Choose year"),
min = 1950, max = 2000, value = 1977),
downloadButton("report", "Generate report")
)))))
ui <- navbarPage("Test",tabPanel("plotly",
bodyplotly))
server <- function(input, output,session) {
output$selected_plot <- renderPlotly({
p <- gapminder %>%
filter(year==input$year) %>%
ggplot( aes(gdpPercap, lifeExp, size = pop, color=continent)) +
geom_point() +
theme_bw()
ggplotly(p)
})
output$downloadreport <- downloadHandler(
# For PDF output, change this to "report.pdf"
filename = "report.html",
content = function(file) {
# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed).
tempReport <- file.path(tempdir(), "report.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
library(rmarkdown)
# Set up parameters to pass to Rmd document
params <- list(input$year)
# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app).
rmarkdown::render(tempReport, pdf_document(),
#output_options=self_contained,
#params = params,
envir = new.env(parent = globalenv())
)
}
)
}
shinyApp(ui = ui, server = server)
库(ggplot2)
图书馆(绘本)
图书馆(gapminder)
图书馆(闪亮)
图书馆(shinydashboard)
图书馆(rmarkdown)
主要是因为文件名是“report.html”?另外,output$downloadreport不应该改为output$report吗?很好。我两个都做了,但仍然不起作用。模板中的yaml头是什么。Rmd?你能在这里定义一个html文件吗?还有,为什么带有输出选项和参数的行被注释掉了?