1

I have a big shiny app and I'm making a downloadable pdf with rmarkdownfrom the content in it. The problem I'm having is that all the plots are in plotlyand I haven't found how to plot 2 plots in the same row of the pdf file, in R it would be a simple subplot but it doesn't work.

This is a toy example of what I have:

shinyApp(
  ui = fluidPage(
    downloadButton("reporte", "Generate report"),
    plotlyOutput("plotTest"),
    plotlyOutput("plotHist")

  ),
  server = function(input, output) {
    library(webshot)

    data = as.data.frame(rnorm(1000))
    plotTest = plot_ly(y = ~rnorm(1000),type = "scatter",mode = "lines")
    plotHist = plot_ly(x = ~rnorm(1000),type = "histogram")
    output$plotTest = renderPlotly({plotTest})
    output$plotHist = renderPlotly({plotHist})

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

        tempReport <- file.path("C:/Users/Alejandro/Documents/test", "report.Rmd")
        file.copy("report.Rmd", tempReport, overwrite = TRUE)

        params <- list(n=plotTest,k=plotHist)

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

report.Rmd:

---
title: "Ensayo Reporte"
output: pdf_document
always_allow_html: yes
params:
  n: NA
  k: NA
---

```{r,echo=FALSE}
library(plotly)
tmpFile <- tempfile(fileext = ".png")
export(params$n, file = tmpFile)
export(params$k, file = tmpFile)
```

Adding the ususal fig.align='center',fig.show='hold' doesn't work i'll just get: Warning: Error in : pandoc document conversion failed with error 43

Alejandro Andrade
  • 2,196
  • 21
  • 40

0 Answers0