Learn R Programming

g2r (version 0.1.0)

change_data: Change Data

Description

Change the data displayed on the chart.

Usage

change_data(proxy, data, ..., figures = NULL)

Arguments

proxy

A g2r proxy as returned by g2Proxy

data

A data.frame or tibble

...

Bare names of column to select.

figures

Index of figures to apply the change to.

Examples

Run this code
# NOT RUN {
library(shiny)

.make_data <- function(){
  dplyr::tibble(
    x = 1:20,
    y = runif(20)
  )
}

ui <- fluidPage(
  fluidRow(
    column(10, g2Output("chart")),
    column(2, actionButton("chg", "chg"))
  )
)

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

  observeEvent(input$chg, {
    g2Proxy("chart") %>% 
      change_data(.make_data(), x, y)
  })
}

# }
# NOT RUN {
shinyApp(ui, server)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab