Dynamically change the data of a shiny plot.

change_data(g, data)

Arguments

g

An object of class g2r or g2Proxy as returned by g2() or g2_proxy().

data

New dataset to replaced the one used to currently plot the data.

Examples

library(shiny)

makeData <- function(){
 data.frame(
   x = runif(100),
   y = runif(100),
   size = runif(100)
 )
}

ui <- fluidPage(
 g2Output("plot"),
 actionButton("change", "Change data")
)

server <- function(input, output){

 output$plot <- renderG2({
   g2(makeData(), asp(x, y, size = size)) %>% 
     fig_point()
 })

 observeEvent(input$change, {
   g2_proxy("plot") %>% 
     change_data(makeData())
 })
}

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