Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dowload pdf in Shiny app #2

Open
myneuronews opened this issue May 6, 2019 · 1 comment
Open

Dowload pdf in Shiny app #2

myneuronews opened this issue May 6, 2019 · 1 comment

Comments

@myneuronews
Copy link

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

@ek-g
Copy link

ek-g commented Jan 7, 2020

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)
            
        },
    )
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants