djpr_girafe: Render ggiraph::girafe() object in a Shiny app and resize...

View source: R/djpr_ggiraph.R

djpr_girafeR Documentation

Render ggiraph::girafe() object in a Shiny app and resize appropriately with the browser window

Description

As a Shiny window (html container) is resized, ggplot2 objects (rendered using plotOutput()) change their widths while retaining their height. By default, ggiraph::girafeOutput() objects don't resize in the same way - they maintain their aspect ratio. These functions render these objects in a way that resizes with the browser window.

Usage

djpr_girafe(ggobj, height = 5, width = 6, ...)

ggiraph_js(col_widths = c(2, 8, 2))

Arguments

ggobj

A ggplot2 object

height

height in inches

width

width in inches

...

Additional options; passed to options argument of ggiraph::girafe.

col_widths

numeric vector of length 3; elements correspond to Bootstrap widths of 3 columns. Must sum to 12.

Details

Note that the title, subtitle, and caption are removed from ggobj using djprtheme::remove_labs().

djpr_girafe() should be used within renderGirafe({}), in place of ggiraph::girafe(), within the server component of a Shiny app.

ggiraph_js() should be called within the Shiny UI, as in fluidPage(ggiraph_js()).

Value

A ggiraph::girafe() object.

Source

https://stackoverflow.com/questions/65267602/can-a-ggiraph-interactive-plot-be-the-size-of-the-window-in-r-shiny and https://stackoverflow.com/questions/45191999/ggiraph-plot-doesnt-resize-to-fit-the-page and https://stackoverflow.com/questions/36995142/get-the-size-of-the-window-in-shiny

Examples

## Not run: 
library(ggplot2)
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  labs(title = "Title will be removed in girafe plot")

djpr_girafe(p, 5, 6)

## End(Not run)

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