| plot_with_settings | R Documentation | 
Universal module for plots with settings for height, width, and download.
plot_with_settings_ui(id)
plot_with_settings_srv(
  id,
  plot_r,
  height = c(600, 200, 2000),
  width = NULL,
  show_hide_signal = reactive(TRUE),
  brushing = FALSE,
  clicking = FALSE,
  dblclicking = FALSE,
  hovering = FALSE,
  graph_align = "left"
)
| id | ( | 
| plot_r | ( | 
| height | ( | 
| width | ( | 
| show_hide_signal | optional, ( | 
| brushing | ( | 
| clicking | ( | 
| dblclicking | ( | 
| hovering | ( | 
| graph_align | ( | 
By default the plot is rendered with 72 dpi. In order to change this, to for example 96 set
options(teal.plot_dpi = 96). The minimum allowed dpi value is 24 and it must be a whole number.
If an invalid value is set then the default value is used and a warning is outputted to the console.
A shiny module.
# Example using a reactive as input to plot_r
library(shiny)
library(ggplot2)
ui <- fluidPage(
  plot_with_settings_ui(
    id = "plot_with_settings"
  )
)
server <- function(input, output, session) {
  plot_r <- reactive({
    ggplot(faithful, aes(x = .data$waiting, y = .data$eruptions)) +
      geom_point()
  })
  plot_with_settings_srv(
    id = "plot_with_settings",
    plot_r = plot_r,
    height = c(400, 100, 1200),
    width = c(500, 250, 750)
  )
}
if (interactive()) {
  shinyApp(ui, server)
}
# Example using a function as input to plot_r
library(lattice)
ui <- fluidPage(
  radioButtons("download_option", "Select the Option", list("ggplot", "trellis", "grob", "base")),
  plot_with_settings_ui(
    id = "plot_with_settings"
  ),
  sliderInput("nums", "Value", 1, 10, 1)
)
server <- function(input, output, session) {
  plot_r <- function() {
    numbers <- seq_len(input$nums)
    if (input$download_option == "ggplot") {
      ggplot(data.frame(n = numbers), aes(.data$n)) +
        geom_bar()
    } else if (input$download_option == "trellis") {
      densityplot(numbers)
    } else if (input$download_option == "grob") {
      tr_plot <- densityplot(numbers)
      ggplotGrob(
        ggplot(data.frame(n = numbers), aes(.data$n)) +
          geom_bar()
      )
    } else if (input$download_option == "base") {
      plot(numbers)
    }
  }
  plot_with_settings_srv(
    id = "plot_with_settings",
    plot_r = plot_r,
    height = c(400, 100, 1200),
    width = c(500, 250, 750)
  )
}
if (interactive()) {
  shinyApp(ui, server)
}
# Example with brushing/hovering/clicking/double-clicking
ui <- fluidPage(
  plot_with_settings_ui(
    id = "plot_with_settings"
  ),
  fluidRow(
    column(4, tags$h3("Brush"), verbatimTextOutput("brushing_data")),
    column(4, tags$h3("Click"), verbatimTextOutput("clicking_data")),
    column(4, tags$h3("DblClick"), verbatimTextOutput("dblclicking_data")),
    column(4, tags$h3("Hover"), verbatimTextOutput("hovering_data"))
  )
)
server <- function(input, output, session) {
  plot_r <- reactive({
    ggplot(faithful, aes(x = .data$waiting, y = .data$eruptions)) +
      geom_point()
  })
  plot_data <- plot_with_settings_srv(
    id = "plot_with_settings",
    plot_r = plot_r,
    height = c(400, 100, 1200),
    brushing = TRUE,
    clicking = TRUE,
    dblclicking = TRUE,
    hovering = TRUE
  )
  output$brushing_data <- renderPrint(plot_data$brush())
  output$clicking_data <- renderPrint(plot_data$click())
  output$dblclicking_data <- renderPrint(plot_data$dblclick())
  output$hovering_data <- renderPrint(plot_data$hover())
}
if (interactive()) {
  shinyApp(ui, server)
}
# Example which allows module to be hidden/shown
library("shinyjs")
ui <- fluidPage(
  useShinyjs(),
  actionButton("button", "Show/Hide"),
  plot_with_settings_ui(
    id = "plot_with_settings"
  )
)
server <- function(input, output, session) {
  plot_r <- plot_r <- reactive(
    ggplot(faithful, aes(x = .data$waiting, y = .data$eruptions)) +
      geom_point()
  )
  show_hide_signal_rv <- reactiveVal(TRUE)
  observeEvent(input$button, show_hide_signal_rv(!show_hide_signal_rv()))
  plot_with_settings_srv(
    id = "plot_with_settings",
    plot_r = plot_r,
    height = c(400, 100, 1200),
    width = c(500, 250, 750),
    show_hide_signal = reactive(show_hide_signal_rv())
  )
}
if (interactive()) {
  shinyApp(ui, server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.