Proxy to dynamically interact with the chart in shiny.

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

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)
}