djpr_plot_ui: Function creates a plot environment containing (optional)...

View source: R/djpr_shiny_plot.R

djpr_plot_uiR Documentation

Function creates a plot environment containing (optional) title and subtitle, chart, notes, and download buttons Takes as input a function to create a ggplot2 or ggirafe object

Description

Function creates a plot environment containing (optional) title and subtitle, chart, notes, and download buttons Takes as input a function to create a ggplot2 or ggirafe object

Usage

djpr_plot_ui(id, height = "400px", width = "100%", interactive = TRUE)

Arguments

id

a Shiny outputId specific to the individual plot.

height

Height of container

width

Width of container; default is "100%"

interactive

Logical; TRUE by default.

Details

To be used in conjunction with djpr_plot_server() Shiny module, which provides the server-side outputs that djpr_plot_ui() expects. See example.

Value

A shiny.tag object creating a plot environment, with labels (title, subtitle, caption) as HTML text, a download button, and optional input controls.

Examples

## Not run: 

library(shiny)
library(ggplot2)

ui <- djpr_page(
  title = "My dashboard",
  djpr_tab_panel(
    title = "First tab",
    djpr_plot_ui("plot")
  )
)

plot_function <- function(data = economics,
                          title = "This is a title",
                          subtitle = "This is a subtitle",
                          caption = "This data comes from the ggplot2 package") {
  data %>%
    ggplot(aes(x = date, y = unemploy)) +
    geom_line() +
    labs(
      title = title,
      subtitle = subtitle,
      caption = caption
    ) +
    theme_minimal(base_size = 14)
}

server <- function(input, output, session) {
  djpr_plot_server("plot",
    plot_function,
    date_slider = TRUE,
    data = ggplot2::economics,
    plt_change = reactive(input$plt_change)
  )
}

shinyApp(ui, server)

## End(Not run)


djpr-data/djprshiny documentation built on May 14, 2023, 1:15 p.m.