d3VennOutput: Shiny bindings for d3Venn

Description Usage Arguments Value Examples

View source: R/d3Venn.R

Description

Output and render functions for using d3Venn within Shiny applications and interactive RMD documents

Usage

1
2
3
d3VennOutput(outputId, width = "100%", height = "400px")

renderD3Venn(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

string, output variable to read the d3Venn diagram from

width, height

Must be a valid CSS unit (like “100%”, “400px”, “auto”) or a number, which will be coerced to a string and have “px” appended.

expr

expression, which creates the d3Venn object.

env

environment in which to evaluate expr.

quoted

boolean, is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.

Value

An output element for use in UI.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
if (requireNamespace("shiny", quietly = TRUE) && interactive()) {
   library(shiny)

   options(device.ask.default = FALSE)

   ui <- fluidPage(
      titlePanel("Venn Diagram"),
      sidebarLayout(
         sidebarPanel(
            sliderInput("a", "Set A:", 10, 100, 10, 10),
            sliderInput("b", "Set B:", 10, 100, 10, 10),
            sliderInput("ovl", "Overlap:", 0, 100, 10, 10, post = "%")
         ),
         mainPanel(
            d3VennOutput("venn")
         )
      )
   )

   server <- function(input, output) {
      output$venn <- renderD3Venn({
         n_A <- req(input$a)
         n_B <- req(input$b)
         n_AB <- round(req(input$ovl) / 100 * min(n_A, n_B))
         if (n_AB > 0) {
            dat <- data.frame(sets = I(list("A", "B", list("A", "B"))),
                              size = c(n_A, n_B, n_AB))
         } else {
            dat <- data.frame(sets = c("A", "B"),
                              size = c(n_A, n_B))
         }
         d3Venn(dat)
      })
   }

   shinyApp(ui, server)
}

thothal/d3Venn documentation built on Dec. 31, 2020, 8:38 a.m.