使用其名称在PDF上打印Shiny Widget

时间:2018-07-20 15:53:13

标签: r pdf shiny r-markdown

是否可以通过在Rmarkdown文件中使用它们的名称来在PDF上打印闪亮的窗口小部件?

请在下面找到一个繁殖示例:

使用以下代码,当我单击“生成报告”时,PDF文件中没有任何内容。如何打印distPlotmy_map小部件而不在Rmarkdown文件上重新找到它们?

library(shiny)
library(plotly)
library(leaflet)

shinyApp(
   ui = fluidPage(
   plotlyOutput("distPlot"),
   leafletOutput("my_map"),
   downloadButton("report", "Generate report")
   ),


server = function(input, output) {


output$distPlot <- renderPlotly({

  x <- c(1:100)
  random_y <- rnorm(100, mean = 0)
  data <- data.frame(x, random_y)

  plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines')
})


output$my_map <- renderLeaflet({

  leaflet() %>% addProviderTiles("OpenStreetMap.Mapnik")
}) 


output$report <- downloadHandler(
  filename = "report.pdf",
  content = function(file) {

    tempReport <- file.path(tempdir(), "report.pdf")
    file.copy("report.Rmd", tempReport, overwrite = TRUE)

    params <- list(n = input$slider)

    rmarkdown::render(tempReport, output_file = file,
                      params = params,
                      envir = new.env(parent = globalenv())
     )
   }
 )
 }
)

这是Rmarkdown文件:

---
title: "Print shiny widget "
output:
  pdf_document: default
  word_document: default

---


 ```{r}

#I would like to print these two widgets 
output$distPlot
output$my_map

 ```

非常感谢!

0 个答案:

没有答案