ggplot-output: Render 'ggplot' module

ggplot-outputR Documentation

Render ggplot module

Description

Display a plot on the client and allow to download it.

Usage

ggplot_output(
  id,
  width = "100%",
  height = "400px",
  downloads = downloads_labels(),
  ...
)

downloads_labels(
  label = ph("download-simple"),
  png = tagList(ph("image"), "PNG"),
  pdf = tagList(ph("file-pdf"), "PDF"),
  svg = tagList(ph("browsers"), "SVG"),
  jpeg = tagList(ph("image"), "JPEG"),
  pptx = tagList(ph("projector-screen"), "PPTX"),
  more = tagList(ph("gear"), i18n("More options"))
)

render_ggplot(
  id,
  expr,
  ...,
  env = parent.frame(),
  quoted = FALSE,
  filename = "export-ggplot",
  resizable = FALSE,
  use_plotly = reactive(FALSE),
  width = reactive(NULL),
  height = reactive(NULL)
)

Arguments

id

Module ID.

width, height

Width / Height of the plot, in the server it has to be a shiny::reactive() function returning a new width/height for the plot.

downloads

Labels for export options, use downloads_labels() or NULL to disable export options.

...

Parameters passed to shiny::plotOutput() (ggplot_output) or shiny::renderPlot() (render_ggplot).

label

Main label for export button

png, pdf, svg, jpeg, pptx

Labels to display in export menu, use NULL to disable specific format.

more

Label for "more" button, allowing to launch export modal.

expr

An expression that generates a ggplot object.

env

The environment in which to evaluate expression.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.

filename

A string of the filename to export WITHOUT extension, it will be added according to type of export.

resizable

Can the chart size be adjusted by the user?

use_plotly

A shiny::reactive() function returning TRUE or FALSE to render the plot with plotly::ggplotly() or not.

Value

Server-side, a reactiveValues with the plot.

Examples


library(shiny)
library(ggplot2)
library(esquisse)


ui <- fluidPage(
  tags$h2("ggplot output"),
  selectInput("var", "Variable:", names(economics)[-1]),
  ggplot_output("MYID", width = "600px")
)

server <- function(input, output, session) {
  
  render_ggplot("MYID", {
    ggplot(economics) + 
      geom_line(aes(date, !!sym(input$var))) + 
      theme_minimal() + 
      labs(
        title = "A cool chart made with ggplot2",
        subtitle = "that you can export in various format"
      )
  })
}

if (interactive())
  shinyApp(ui, server)

esquisse documentation built on Sept. 18, 2024, 5:09 p.m.