Debian Codegraph @

R/viewer.R

raw
1
2 #' Viewer options
3 #'
4 #' Use these functions to control where the gadget is displayed in RStudio (or
5 #' other R environments that emulate RStudio's viewer pane/dialog APIs). If
6 #' viewer APIs are not available in the current R environment, then the gadget
7 #' will be displayed in the system's default web browser (see
8 #' [utils::browseURL()]).
9 #'
10 #' @return A function that takes a single `url` parameter, suitable for
11 #' passing as the `viewer` argument of [runGadget()].
12 #'
13 #' @rdname viewer
14 #' @name viewer
15 NULL
16
17 #' @param minHeight The minimum height (in pixels) desired to show the gadget in
18 #' the viewer pane. If a positive number, resize the pane if necessary to show
19 #' at least that many pixels. If `NULL`, use the existing viewer pane
20 #' size. If `"maximize"`, use the maximum available vertical space.
21 #' @rdname viewer
22 #' @export
23 paneViewer <- function(minHeight = NULL) {
24 viewer <- getOption("viewer")
25 if (is.null(viewer)) {
26 utils::browseURL
27 } else {
28 function(url) {
29 viewer(url, minHeight)
30 }
31 }
32 }
33
34 #' @param dialogName The window title to display for the dialog.
35 #' @param width,height The desired dialog width/height, in pixels.
36 #' @rdname viewer
37 #' @export
38 dialogViewer <- function(dialogName, width = 600, height = 600) {
39 viewer <- getOption("shinygadgets.showdialog")
40 if (is.null(viewer)) {
41 utils::browseURL
42 } else {
43 function(url) {
44 viewer(dialogName, url, width = width, height = height)
45 }
46 }
47 }
48
49 #' @param browser See [utils::browseURL()].
50 #' @rdname viewer
51 #' @export
52 browserViewer <- function(browser = getOption("browser")) {
53 function(url) {
54 utils::browseURL(url, browser = browser)
55 }
56 }