save-ggplot-module: Save 'ggplot' module

Description Usage Arguments Value Examples

Description

Save a ggplot object in various format and resize it before saving.

Usage

1
2
3
4
5

Arguments

id

Module ID.

title

Modal's title.

plot_rv

A reactiveValues with a slot plot containing a ggplot object.

Value

No value. Use in UI & server of shiny application.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
library(shiny)
library(ggplot2)
library(shinyWidgets)


ui <- fluidPage(
  tags$h2("Save a ggplot"),
  selectInput("var", "Variable:", names(economics)[-1]),
  plotOutput("plot", width = "600px"),
  actionButton("save", "Save this plot")
)

server <- function(input, output, session) {
  
  rv <- reactiveValues(plot = NULL)
  
  output$plot <- renderPlot({
    rv$plot <- ggplot(economics) + 
      geom_line(aes(date, !!sym(input$var))) + 
      theme_minimal()
    rv$plot
  })
  
  observeEvent(input$save, {
    save_ggplot_modal("ID", "Save plot")
  })
  save_ggplot_server("ID", rv)
}

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

singha53/esquisse documentation built on Dec. 23, 2021, 2:29 a.m.