0

How can I use a download button instead of hc_exporting function to download a highchart in shiny?

    library(shiny)
library(shinydashboard)
library(highcharter)
library(shinyWidgets)

RecruitmentFunneldb_struct <-
  structure(list(
    yyyy = c(2019L, 2019L, 2019L, 2019L, 2019L, 2019L),
    stages = c(
      "Phone Scrining",
      "Interview",
      "Offer",
      "Pre-Onboarding",
      "Post-Joining",
      "Joined"
    ),
    pop = c(8L, 25L, 23L, 32L, 8L, 4L)
  ),
  row.names = c(NA,
                6L),
  class = "data.frame")


ui <-
  dashboardPage(
    dashboardHeader(
      title = HTML("Analytic view - Recruitment"),
      titleWidth = 280
    ),
    dashboardSidebar(disable = T),
    dashboardBody(fluidPage(fluidRow(
      box(
        title = fluidRow(
          column(10, "Recruitment Funnel"),
          column(
            2,
            align = "right",
            downloadButton("download", label = NULL, class = "butt1"),
            tags$head(
              tags$style(
                ".butt1{display: inline-block;}  .butt1{font-size: 20px;} .butt1{border: none;} .butt1{padding-top: 1px} .butt1{background-color: transperent .butt1{padding-right: 50px}}"
              )
            )
            
          )
        ),
        solidHeader = T,
        width = 4,
        collapsible = F,
        highchartOutput("Recruitment_Funnel", height = "240px")
      )
      
    )))
  )

server <- function(input, output, session) {
  output$Recruitment_Funnel <- renderHighchart({
    Reserve_Data <- RecruitmentFunneldb_struct %>% arrange(-pop)
    Reserve_Data %>%
      hchart("funnel", hcaes(x = stages, y = pop))
  })
  
  output$download <- downloadHandler(
    filename = function() {
      paste("Funnel", ".", "pdf")
    },
    content = function(file) {
      pdf(file)
      output$Recruitment_Funnel()
      dev.off()
    }
  )
  
}
shinyApp(ui, server)
  • Welcome to SO! Can you please make a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), in your case a shiny app that runs, so use an example data set instead of your database connection – starja Aug 08 '20 at 06:13
  • I have update runnable code please check this. – Milind Shingote Aug 08 '20 at 07:45
  • Here is some documentation from highcharts. Unfortunately my JS knowledge is not good enough to combine it with shiny: https://www.highcharts.com/docs/export-module/export-module-overview, https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/members/chart-exportchart-filename/ – starja Aug 08 '20 at 10:07
  • If anyone know how to combine this code then please tell me because also i have no idea about JS. – Milind Shingote Aug 08 '20 at 12:31

0 Answers0