djpr_plot_server: Shiny module to create DJPR plot environment.

View source: R/djpr_shiny_plot.R

djpr_plot_serverR Documentation

Shiny module to create DJPR plot environment.

Description

Server-side companion to djpr_plot_ui().

Usage

djpr_plot_server(
  id,
  plot_function,
  data,
  plt_change,
  date_slider = TRUE,
  date_slider_value_min = NULL,
  check_box_options = NULL,
  check_box_selected = check_box_options,
  check_box_var = series,
  download_button = TRUE,
  width_percent = 100,
  height_percent = 100,
  interactive = TRUE,
  convert_lazy = TRUE,
  ...
)

Arguments

id

a Shiny outputId specific to the individual plot.

plot_function

A function (without ⁠()⁠) that creates a ggplot2 object. Function must contain a data argument that takes a data.frame.

data

data frame containing data to visualise

plt_change

This should be: reactive(input$plt_change). Note that this reactive is created by ggiraph_js() which is called by djpr_tab_panel(). djpr_plot_server() should only be called in apps that feature a djpr_tab_panel().

date_slider

Logical; TRUE if you want a date slider to be shown. If TRUE, your data must contain a date column.

date_slider_value_min

NULL by default. Specify a date to modify the first (minimum) selected date in the date slider. A date slider (if present) will have two selected values, corresponding to the start and end of the date range to be visualised. By default, these values are the minimum and maximum of the date columns of data. Supplying a non-NULL value to this argument overrides the minimum value.

check_box_options

A character vector containing values to include in a check box. NULL by default, which suppresses the check box.

check_box_selected

A character vector containing values of the check box that should be selected by default.

check_box_var

name of column in data that contains the levels included in check_box_options. series by default.

download_button

logical; TRUE by default. When TRUE, a download button is displayed.

width_percent

Width of plot object, as a percentage of the standard

height_percent

Height of plot object, as a percentage of the standard

interactive

logical; TRUE by default. When TRUE, plot will be rendered as an interactive ggiraph object; when FALSE a static ggplot will be rendered.

convert_lazy

logical; TRUE by default. When TRUE, lazy data will be converted so that a data.frame is passed to plot functions.

...

arguments passed to plot_function

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.