Learn R Programming

billboarder (version 0.5.2)

bb_export: Export a Billboard to PNG

Description

Export a Billboard to PNG

Usage

bb_export(bb, filename = NULL, download_label = "Export (.png)", ...)

Value

A `billboard` `htmlwidget` object.

Arguments

bb

A [billboarder()] `htmlwidget` object or a [billboarderProxy()] `htmlwidget` object.

filename

A string of the filename, excluding extension (will be `".png"`).

download_label

Label to appear on the link to download PNG.

...

Additional arguments (not used).

Examples

Run this code
# Add a button to download as PNG:

data("equilibre_mensuel")
billboarder() %>%
  bb_linechart(
    data = equilibre_mensuel,
    mapping = bbaes(date, solde),
    type = "spline"
  ) %>%
  bb_x_axis(
    tick = list(format = "%Y-%m", fit = FALSE)
  ) %>%
  bb_export(
    filename = "my-awesome-chart",
    download_label = "Click to download"
  )

# In Shiny, you can use proxy:

if (interactive()) {
  library(shiny)
  library(billboarder)

  ui <- fluidPage(
    fluidRow(
      column(
        width = 8, offset = 2,
        tags$h1("Export billboard as PNG via Proxy"),
        billboarderOutput(outputId = "mybb"),
        actionButton(
          inputId = "export",
          label = "Export",
          icon = icon("download")
        )
      )
    )
  )

  server <- function(input, output, session) {

    output$mybb <- renderBillboarder({
      data("prod_par_filiere")
      billboarder() %>%
        bb_barchart(
          data = prod_par_filiere[, c("annee", "prod_hydraulique")],
          color = "#102246"
        ) %>%
        bb_y_grid(show = TRUE)
    })

    observeEvent(input$export, {
      billboarderProxy(shinyId = "mybb") %>%
        bb_export(filename = "my-billboard-chart")
    })

  }

  shinyApp(ui, server)
}

Run the code above in your browser using DataLab