jackwasey / PRISMAstatement

Plot Flow Charts According to the PRISMA Statement
GNU General Public License v3.0
19 stars 2 forks source link

Dowload pdf in Shiny app #2

Open myneuronews opened 5 years ago

myneuronews commented 5 years ago

Any suggestions on how to download pdf or png of flowchart with downloadhandler in shiny app?

ek-g commented 4 years ago

In case you are still looking for one, @myneuronews, here is a solution without custom labels or any other optional arguments.

library(shiny)
library(PRISMAstatement)

prisma_pdf <- function(x, filename = "prisma.pdf") {
    utils::capture.output({
        rsvg::rsvg_pdf(svg = charToRaw(DiagrammeRsvg::export_svg(x)),
                       file = filename)
    })
    invisible()
}

shinyApp(ui <- fluidPage(
    numericInput("found", "Found in databases", 10),
    numericInput("found_other", "Found in other sources", 1),
    numericInput("no_dupes", "Without duplicates", 5),
    numericInput("screened", "Screened", 5),
    numericInput("screen_exclusions", "Screening exclusions", 1),
    numericInput("full_text", "Full-texts read", 4),
    numericInput("full_text_exclusions", "Full-text exclusions", 2),
    numericInput("qualitative", "Qualitative synthesis", 2),
    numericInput("quantitative", "Quantitative synthesis", 1),
    downloadButton("download", "Download PRISMA-Flow Diagram")
),

server <- function(input, output) {
    output$download <- downloadHandler(
        filename = "prisma.pdf",
        content = function(file){
            prisma_pdf(
                prisma(found = input$found,
                             found_other = input$found_other,
                             no_dupes = input$no_dupes,
                             screened = input$screened,
                             screen_exclusions = input$screen_exclusions,
                             full_text = input$full_text,
                             full_text_exclusions = input$full_text_exclusions,
                             qualitative = input$qualitative,
                             quantitative = input$quantitative), file)

        },
    )
})