g2_proxy: Shiny Proxy

Description Usage Arguments Examples

View source: R/proxy.R

Description

Proxy to dynamically interact with the chart in shiny.

Usage

1
g2_proxy(id, ..., data = NULL, session = shiny::getDefaultReactiveDomain())

Arguments

id

Id of chart to interact with.

...

Aspects, see asp().

data

Data.frame containing data to plot.

session

A valid shiny session.

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
library(shiny)

dataset <- data.frame(x = 1:100, y = runif(100, 1, 100))

ui <- fluidPage(
  g2Output("plot"),
  actionButton("add", "Add figure")
)

server <- function(input, output, session) {
  output$plot <- renderG2({
    g2(dataset, asp(x, y)) %>%
      fig_point()
  })

  observeEvent(input$add, {
    df <- data.frame(x = 1:100, y = runif(100, 1, 100))
    g2_proxy("plot", data = df) %>%
      fig_point(asp(x, y)) %>%
      render()
  })
}

if (interactive()) {
  shinyApp(ui, server)
}

devOpifex/g2r documentation built on Jan. 16, 2022, 12:36 a.m.