change_data: Change the data

Description Usage Arguments Examples

View source: R/proxy.R

Description

Dynamically change the data of a shiny plot.

Usage

1

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

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

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