# Event\_data in 4.9.0 missing code if data is NULL

**URL:** <https://community.plotly.com/t/event-data-in-4-9-0-missing-code-if-data-is-null/23767>\
**Category:** Plotly R\
**Created:** [May 23, 2019, 12:45pm UTC](https://community.plotly.com/t/event-data-in-4-9-0-missing-code-if-data-is-null/23767 "2019-05-23T12:45:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarkvDijk](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@MarkvDijk](https://community.plotly.com/u/MarkvDijk)\
**Post date:** [May 23, 2019, 12:45pm UTC](https://community.plotly.com/t/event-data-in-4-9-0-missing-code-if-data-is-null/23767/1 "2019-05-23T12:45:29Z")

</div>

It seems that in the new R plotly 4.9.0 version, there is a change in the event\_data code that causes errors if the plot is not yet build.  
i.e. a situation where a plot\_ly plot is not build because the data it needs is not yet available in the plot by means of a req(data) inside the plot\_ly() block. The observeEvent(event\_data(“plotly\_click”, source = ‘A\_plot’), { …}) used to work fine before, but now throws errors, and does so for all forms of event\_data.

example of an error message I get now:

> Warning: The ‘plotly\_click’ event tied a source ID of ‘plotlyplot.testplot’ is not registered. In order to obtain this event data, please add `event_register(p, 'plotly_click')` to the plot (`p`) that you wish to obtain event data from.

The app below demonstrates the problem with version 4.9.0:

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

rm(list = ls(), envir = environment()) ## to prevent cross over from old runs

testData = data.frame(day = sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 24), frequency = sample(1:5, 24, replace = T ), datecoloring = sample(1:2, 24, replace = T ))
testData$dayPOSIXct <- as.POSIXct(testData$day)

dateRangeMin <- min(testData$day)
dateRangeMax <- max(testData$day)

ui <- fluidPage(
  actionButton(inputId = 'Load', label = 'Data'),
  plotlyOutput('testplot', width = 700, height = 500)

)

server <- function(input, output,session) {

  values <- reactiveValues()

  observeEvent(input$Load, { 
    values$testData <- testData
    })

  output$testplot <- renderPlotly({ 
    req(values$testData)
    p <- plot_ly(data = values$testData, source = 'testplot',
                  color = as.factor(values$testData$datecoloring), colors = c('#339fff', '#eaf5ff'),
                  opacity= 0.5, showlegend = T,
                  marker = list(line = list(width = 2, color = '#0000ff')),
                  hoverinfo = "text",
                  text = ~paste('Files:', values$testData$frequency, '<br>Date:', format(values$testData$day, format = '%Y-%m-%d'), sep = ' '))%>%
      add_bars( x = ~dayPOSIXct, y = ~frequency, type = "bar", width = 36000000
      )
    p
  })

  observeEvent(event_data("plotly_relayout", source = "testplot"),{
    #any code here, doesn't matter, bug happens already
  })

}

shinyApp(ui, server)

```
