# What is the most performant way to update a graph with new data?

**URL:** <https://community.plotly.com/t/what-is-the-most-performant-way-to-update-a-graph-with-new-data/639>\
**Category:** plotly.js\
**Created:** [March 14, 2016, 9:33am UTC](https://community.plotly.com/t/what-is-the-most-performant-way-to-update-a-graph-with-new-data/639 "2016-03-14T09:33:58Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![ismirsehregal](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/ismirsehregal/32/6794_2.png) [@ismirsehregal](https://community.plotly.com/u/ismirsehregal)\
**Post date:** [February 7, 2020, 4:03pm UTC](https://community.plotly.com/t/what-is-the-most-performant-way-to-update-a-graph-with-new-data/639/6 "2020-02-07T16:03:21Z")

</div>

It’s been a while but however, here is an R example for replacing data using Plotly.restyle:

```auto
library(shiny)
library(plotly)

initial_plot <- plot_ly(
  type = 'scatter',
  mode = 'lines',
  line = list(color = '#1166FF',
              width = 3)
)

ui <- fluidPage(
  plotlyOutput("myPlot")
)

server <- function(input, output, session) {
  
  myData <- reactiveValues(x = 1, y = runif(1, min=1, max=10))
  
  output$myPlot <- renderPlotly({
    initial_plot
  })
  
  myPlotProxy <- plotlyProxy("myPlot", session)

  observe({
    invalidateLater(1000)
    myData$x <- isolate(c(myData$x, length(myData$x)+1))
    myData$y <- isolate(c(myData$y, runif(1, min=1, max=10)))
    print(myData$x)
    print(myData$y)
  })
  
  observe({
    plotlyProxyInvoke(myPlotProxy, "restyle", list(x = list(myData$x), y = list(myData$y)))
  })
  
}

shinyApp(ui, server)

```

 ![screen](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/1/1fd93b4ffc16709abcf9de910afa778dcca8c401.gif)

---

_[View the full topic](https://community.plotly.com/t/what-is-the-most-performant-way-to-update-a-graph-with-new-data/639)._
